SHIMODA Piro Hiroshi
null+****@clear*****
Sat Oct 4 20:24:23 JST 2014
SHIMODA "Piro" Hiroshi 2014-10-04 20:24:23 +0900 (Sat, 04 Oct 2014) New Revision: f78a08354ed08093da3c67406819f3dbfab02003 https://github.com/droonga/drnbench/commit/f78a08354ed08093da3c67406819f3dbfab02003 Message: Add "--escape" option to escape output for URL parameter Modified files: bin/drnbench-extract-searchterms Modified: bin/drnbench-extract-searchterms (+15 -1) =================================================================== --- bin/drnbench-extract-searchterms 2014-10-04 19:58:02 +0900 (e13c30f) +++ bin/drnbench-extract-searchterms 2014-10-04 20:24:23 +0900 (2e5f6f4) @@ -22,6 +22,7 @@ require "json" options = OpenStruct.new options.column_index = 0 +options.escape = false option_parser = OptionParser.new do |parser| parser.version = Drnbench::VERSION @@ -31,17 +32,30 @@ option_parser = OptionParser.new do |parser| "(#{options.output_column_index})") do |index| options.column_index = index end + parser.on("--escape", + "Escape output for URL parameter") do + options.escape = true + end end groonga_select_result_files = option_parser.parse!(ARGV) +def sanitize_for_param(value) + value.to_s + .gsub(/[:;]/, " ") + .strip + .gsub(/ +/, "%20") +end + def output_column_value(select_result, column_index) select_result = JSON.parse(select_result) body = select_result[1] search_result = body.first records = search_result[2..-1] records.each do |record| - puts record[column_index] + value = record[column_index] + value = sanitize_for_param(value) if options.escape + puts(value) end end -------------- next part -------------- HTML����������������������������... 다운로드