From 02398e771b45155d8fb2c73bfd09aa4f55908c21 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Sat, 30 Jan 2021 20:52:18 +0900 Subject: [PATCH] Fix `Process.parse_argument` behavior against a quote in a word Fixed #10306 Thanks @erdnaxeli for reporting. --- spec/std/process_spec.cr | 3 +++ src/process/shell.cr | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/std/process_spec.cr b/spec/std/process_spec.cr index 77ac0da19944..4cda37bab562 100644 --- a/spec/std/process_spec.cr +++ b/spec/std/process_spec.cr @@ -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 diff --git a/src/process/shell.cr b/src/process/shell.cr index a356302fe430..fa5f31c9bed7 100644 --- a/src/process/shell.cr +++ b/src/process/shell.cr @@ -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 != '\''