Kouhei Sutou
null+****@clear*****
Mon Oct 14 23:37:47 JST 2013
Kouhei Sutou 2013-10-14 23:37:47 +0900 (Mon, 14 Oct 2013) New Revision: 951b09ccd4e39c5ce8649b7b83618f667fea58da https://github.com/groonga/groonga-command-parser/commit/951b09ccd4e39c5ce8649b7b83618f667fea58da Message: Add missing backslash escape in command line arguments It seems that we should implement groonga command line parser instead of using Shellwords.shellwords. Modified files: lib/groonga/command/parser.rb Modified: lib/groonga/command/parser.rb (+32 -0) =================================================================== --- lib/groonga/command/parser.rb 2013-09-29 18:58:28 +0900 (d0061ce) +++ lib/groonga/command/parser.rb 2013-10-14 23:37:47 +0900 (530df80) @@ -370,6 +370,18 @@ module Groonga def parse_command_line(command_line) name, *arguments = Shellwords.shellwords(command_line) + arguments = arguments.collect do |argument| + # TODO: Groonga supports backslash escape in both single + # quoted argument and double quoted argument ('...' and + # "..."). We should not unescape except single quoted + # argument ('...') because Shellwords.shellwords unescape it + # in double quoted argument. But we can't determine whether + # the argument is single quoted or not after + # Shellwords.shellwords... And groonga supports '\n' -> new line + # conversion. It isn't done by Shellwords.shellwords. + # Should we implement Shellwords.shellwords by ourselves? + unescape_argument_in_command_line(argument) + end pair_arguments = {} ordered_arguments = [] until arguments.empty? @@ -386,6 +398,26 @@ module Groonga command end + def unescape_argument_in_command_line(argument) + argument.gsub(/\\(.)/) do + character = $1 + case character + when "b" + "\b" + when "f" + "\f" + when "n" + "\n" + when "r" + "\r" + when "t" + "\t" + else + character + end + end + end + def reset @command = nil @loading = false -------------- next part -------------- HTML����������������������������...Download