From 0baea09278c55c489130bc64fbf4a9be38143bbe Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 16 Oct 2017 21:46:37 +0300 Subject: [PATCH 1/2] Add spec for Shelwords.shelwords bug with backslash escaping --- library/shellwords/shellwords_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/shellwords/shellwords_spec.rb b/library/shellwords/shellwords_spec.rb index aa35c1a5c3..f9560d8b48 100644 --- a/library/shellwords/shellwords_spec.rb +++ b/library/shellwords/shellwords_spec.rb @@ -26,4 +26,11 @@ it "raises ArgumentError when single quoted strings are misquoted" do lambda { shellwords("a 'b c d e") }.should raise_error(ArgumentError) end + + ruby_version_is '2.4' do + # https://bugs.ruby-lang.org/issues/10055 + it %Q{ treats the backslash as escape character only when followed by one of the following characters: $ ` " \ " } do + shellsplit('printf "%s\\n"').should == ['printf', '%s\n'] + end + end end From 6fdb8e9417dde8cb87f9a45e5abef6aebb210b4f Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Wed, 18 Oct 2017 11:06:58 +0300 Subject: [PATCH 2/2] Code review. Fix spec description --- library/shellwords/shellwords_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/shellwords/shellwords_spec.rb b/library/shellwords/shellwords_spec.rb index f9560d8b48..f8ab0cbd9d 100644 --- a/library/shellwords/shellwords_spec.rb +++ b/library/shellwords/shellwords_spec.rb @@ -29,8 +29,8 @@ ruby_version_is '2.4' do # https://bugs.ruby-lang.org/issues/10055 - it %Q{ treats the backslash as escape character only when followed by one of the following characters: $ ` " \ " } do - shellsplit('printf "%s\\n"').should == ['printf', '%s\n'] + it "matches POSIX sh behavior for backslashes within double quoted strings" do + shellsplit('printf "%s\n"').should == ['printf', '%s\n'] end end end