Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Process.parse_argument behavior against a quote in a word #10337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spec/std/process_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ describe Process do
it { Process.parse_arguments(%q('foo\ bar')).should eq(["foo\\ bar"]) }
it { Process.parse_arguments("\\").should eq(["\\"]) }
it { Process.parse_arguments(%q["foo bar" '\hello/' Fizz\ Buzz]).should eq(["foo bar", "\\hello/", "Fizz Buzz"]) }
it { Process.parse_arguments(%q[foo"bar"baz]).should eq(["foobarbaz"]) }
it { Process.parse_arguments(%q[foo'bar'baz]).should eq(["foobarbaz"]) }
it { Process.parse_arguments(%(this 'is a "'very wei"rd co"m"mand please" don't do t'h'a't p"leas"e)).should eq(["this", "is a \"very", "weird command please", "dont do that", "please"]) }

it "raises an error when double quote is unclosed" do
expect_raises ArgumentError, "Unmatched quote" do
Expand Down
2 changes: 1 addition & 1 deletion src/process/shell.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Process
reader.next_char
end

until (char = reader.current_char) == quote || (!quote && char.ascii_whitespace?)
until (char = reader.current_char) == quote || (!quote && (char.ascii_whitespace? || char.in?('\'', '"')))
break unless reader.has_next?
reader.next_char
if char == '\\' && quote != '\''
Expand Down