Fix the handling of the backslash in double quotes

* lib/shellwords.rb (Shellwords#shellsplit): Fix the handling of
  the backslash in double quotes to conform to the standard.
  [ruby-core:63807] [Bug #10055]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2016-11-05 04:58:48 +00:00
parent 7a78133a41
commit 2da5ae4232
3 changed files with 34 additions and 8 deletions

View file

@ -40,12 +40,24 @@ class TestShellwords < Test::Unit::TestCase
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)
[
[
%q{/a//b///c////d/////e/ "/a//b///c////d/////e/ "'/a//b///c////d/////e/ '/a//b///c////d/////e/ },
'a/b/c//d//e /a/b//c//d///e/ /a//b///c////d/////e/ a/b/c//d//e '
],
[
%q{printf %s /"/$/`///"/r/n},
'printf', '%s', '"$`/"rn'
],
[
%q{printf %s "/"/$/`///"/r/n"},
'printf', '%s', '"$`/"/r/n'
]
].map { |strs|
cmdline, *expected = strs.map { |str| str.tr("/", "\\\\") }
assert_equal expected, shellwords(cmdline)
}
end
def test_stringification