Permalink
Browse files

fix not to remove backslash in command argument

  • Loading branch information...
takahashim committed Jun 16, 2012
1 parent b8e738b commit cb8c3496feeacd3d772f20a00efa583e6038ac28
Showing with 19 additions and 1 deletion.
  1. +5 −1 lib/review/compiler.rb
  2. +14 −0 test/test_compiler.rb
View
@@ -444,7 +444,11 @@ def parse_args(str, name=nil)
scanner = StringScanner.new(str)
words = []
while word = scanner.scan(/(\[\]|\[.*?[^\\]\])/)
- words << word[1..-2].gsub(/\\(.)/){$1}
+ w2 = word[1..-2].gsub(/\\(.)/){
+ ch = $1
+ (ch == "]" or ch == "\\") ? ch : "\\" + ch
+ }
+ words << w2
end
if !scanner.eos?
error "argument syntax error: #{scanner.rest} in #{str.inspect}"
View
@@ -26,5 +26,19 @@ def test_parse_args_with_brace2
assert_equal ["f]o]o","bar"], args
end
+ def test_parse_args_with_backslash
+ args = @c.__send__(:parse_args, "[foo][bar\\buz]")
+ assert_equal ["foo","bar\\buz"], args
+ end
+
+ def test_parse_args_with_backslash2
+ args = @c.__send__(:parse_args, "[foo][bar\\#\\[\\!]")
+ assert_equal ["foo","bar\\#\\[\\!"], args
+ end
+
+ def test_parse_args_with_backslash3
+ args = @c.__send__(:parse_args, "[foo][bar\\\\buz]")
+ assert_equal ["foo","bar\\buz"], args
+ end
end

0 comments on commit cb8c349

Please sign in to comment.