diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-06-20 13:19:48 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-27 07:43:32 -0700 |
commit | 43a16c98df392e726040f0331a3e09d00c53d513 (patch) | |
tree | 1ee0c11ecc50da5c9e14597838ce035341a895b7 | |
parent | 2b6a9f3a1ffcdb00bf89798979d475c6d189d419 (diff) | |
download | ruby-43a16c98df392e726040f0331a3e09d00c53d513.tar.gz |
Do not escape + in Shellwords.escape
+ is not a character that requires escaping in Bourne sh.
Fixes [Bug #14429]
-rw-r--r-- | lib/shellwords.rb | 2 | ||||
-rw-r--r-- | test/test_shellwords.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/shellwords.rb b/lib/shellwords.rb index eb5fa2d226..a125b8968c 100644 --- a/lib/shellwords.rb +++ b/lib/shellwords.rb @@ -147,7 +147,7 @@ module Shellwords # Treat multibyte characters as is. It is the caller's responsibility # to encode the string in the right encoding for the shell # environment. - str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1") + str.gsub!(/([^A-Za-z0-9_\-.,:+\/@\n])/, "\\\\\\1") # A LF cannot be escaped with a backslash because a backslash + LF # combo is regarded as a line continuation and simply ignored. diff --git a/test/test_shellwords.rb b/test/test_shellwords.rb index 16949c02d3..86971b7237 100644 --- a/test/test_shellwords.rb +++ b/test/test_shellwords.rb @@ -68,6 +68,11 @@ class TestShellwords < Test::Unit::TestCase assert_equal "ps -p #{$$}", joined end + def test_shellescape + assert_equal "''", shellescape('') + assert_equal "\\^AZaz09_\\\\-.,:/@'\n'+\\'\\\"", shellescape("^AZaz09_\\-.,:\/@\n+'\"") + end + def test_whitespace empty = '' space = " " |