ruby-changes:22236
From: knu <ko1@a...>
Date: Fri, 13 Jan 2012 03:42:15 +0900 (JST)
Subject: [ruby-changes:22236] knu:r34285 (trunk): * lib/shellwords.rb (Shellwords#shellsplit): Fix a bug where
knu 2012-01-13 03:42:03 +0900 (Fri, 13 Jan 2012) New Revision: 34285 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34285 Log: * lib/shellwords.rb (Shellwords#shellsplit): Fix a bug where consecutive backslashes in double quotes are all removed except the one at the tail. Modified files: trunk/ChangeLog trunk/lib/shellwords.rb trunk/test/test_shellwords.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34284) +++ ChangeLog (revision 34285) @@ -1,3 +1,9 @@ +Fri Jan 13 03:38:36 2012 Akinori MUSHA <knu@i...> + + * lib/shellwords.rb (Shellwords#shellsplit): Fix a bug where + consecutive backslashes in double quotes are all removed except + the one at the tail. + Fri Jan 13 03:28:00 2012 Luis Lavena <luislavena@g...> * ext/socket/extconf.rb (if ipv6): only define _WIN32_WINNT if was not Index: lib/shellwords.rb =================================================================== --- lib/shellwords.rb (revision 34284) +++ lib/shellwords.rb (revision 34285) @@ -41,7 +41,7 @@ line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do |word, sq, dq, esc, garbage, sep| raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage - field << (word || sq || (dq || esc).gsub(/\\(?=.)/, '')) + field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1')) if sep words << field field = '' Index: test/test_shellwords.rb =================================================================== --- test/test_shellwords.rb (revision 34284) +++ test/test_shellwords.rb (revision 34285) @@ -38,6 +38,15 @@ end end + def test_backslashes + cmdline, expected = [ + %q{/a//b///c////d/////e/ "/a//b///c////d/////e/ "'/a//b///c////d/////e/ '/a//b///c////d/////e/ }, + %q{a/b/c//d//e a/b/c//d//e /a//b///c////d/////e/ a/b/c//d//e } + ].map { |str| str.tr("/", "\\\\") } + + assert_equal [expected], shellwords(cmdline) + end + def test_multibyte_characters # This is not a spec. It describes the current behavior which may # be changed in future. There would be no multibyte character -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/