From e6d520d4c948443c961f10997af5a1bccd2ab7b1 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 20 Jun 2019 13:19:48 -0700 Subject: [PATCH] Do not escape + in Shellwords.escape + is not a character that requires escaping in Bourne sh. Fixes [Bug #14429] --- lib/shellwords.rb | 2 +- test/test_shellwords.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 @@ def shellescape(str) # 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 @@ def test_stringification 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 = " " -- 2.21.0