Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: brush-parser/src/word.rs
expression: "test_parse(\"\\\"$(cat <<'EOF'\\n`hello`\\nEOF\\n)\\\"\")?"
---
ParseTestResults(
input: "\"$(cat <<\'EOF\'\n`hello`\nEOF\n)\"",
result: [
WordPieceWithSource(
piece: DoubleQuotedSequence([
WordPieceWithSource(
piece: CommandSubstitution("cat <<\'EOF\'\n`hello`\nEOF\n"),
start_index: 1,
end_index: 28,
),
]),
start_index: 0,
end_index: 29,
),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: brush-parser/src/word.rs
expression: "test_parse(\"\\\"$(cat <<'EOF'\\n\\\"hello\\\"\\nEOF\\n)\\\"\")?"
---
ParseTestResults(
input: "\"$(cat <<\'EOF\'\n\"hello\"\nEOF\n)\"",
result: [
WordPieceWithSource(
piece: DoubleQuotedSequence([
WordPieceWithSource(
piece: CommandSubstitution("cat <<\'EOF\'\n\"hello\"\nEOF\n"),
start_index: 1,
end_index: 28,
),
]),
start_index: 0,
end_index: 29,
),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: brush-parser/src/word.rs
expression: "test_parse(\"\\\"$(cat <<'EOF'\\n'hello'\\nEOF\\n)\\\"\")?"
---
ParseTestResults(
input: "\"$(cat <<\'EOF\'\n\'hello\'\nEOF\n)\"",
result: [
WordPieceWithSource(
piece: DoubleQuotedSequence([
WordPieceWithSource(
piece: CommandSubstitution("cat <<\'EOF\'\n\'hello\'\nEOF\n"),
start_index: 1,
end_index: 28,
),
]),
start_index: 0,
end_index: 29,
),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: brush-parser/src/word.rs
expression: "test_parse(\"\\\"$(cat <<'EOF'\\na ` b\\nEOF\\n)\\\"\")?"
---
ParseTestResults(
input: "\"$(cat <<\'EOF\'\na ` b\nEOF\n)\"",
result: [
WordPieceWithSource(
piece: DoubleQuotedSequence([
WordPieceWithSource(
piece: CommandSubstitution("cat <<\'EOF\'\na ` b\nEOF\n"),
start_index: 1,
end_index: 26,
),
]),
start_index: 0,
end_index: 27,
),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: brush-parser/src/word.rs
expression: "test_parse(\"\\\"$(cat <<'EOF'\\nit's here\\nEOF\\n)\\\"\")?"
---
ParseTestResults(
input: "\"$(cat <<\'EOF\'\nit\'s here\nEOF\n)\"",
result: [
WordPieceWithSource(
piece: DoubleQuotedSequence([
WordPieceWithSource(
piece: CommandSubstitution("cat <<\'EOF\'\nit\'s here\nEOF\n"),
start_index: 1,
end_index: 30,
),
]),
start_index: 0,
end_index: 31,
),
],
)
33 changes: 32 additions & 1 deletion brush-parser/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ peg::parser! {

pub(crate) rule command_piece() -> () =
word_piece(<[')']>, true /*in_command*/) {} /
([' ' | '\t'])+ {}
([' ' | '\t'])+ {} /
['\'' | '`'] {}

rule backquoted_command() -> String =
chars:(backquoted_char()*) { chars.into_iter().collect() }
Expand Down Expand Up @@ -1263,6 +1264,36 @@ mod tests {
Ok(())
}

#[test]
fn parse_command_sub_with_unbalanced_single_quote() -> Result<()> {
assert_ron_snapshot!(test_parse("\"$(cat <<'EOF'\nit's here\nEOF\n)\"")?);
Ok(())
}

#[test]
fn parse_command_sub_with_unbalanced_backtick() -> Result<()> {
assert_ron_snapshot!(test_parse("\"$(cat <<'EOF'\na ` b\nEOF\n)\"")?);
Ok(())
}

#[test]
fn parse_command_sub_with_balanced_double_quotes() -> Result<()> {
assert_ron_snapshot!(test_parse("\"$(cat <<'EOF'\n\"hello\"\nEOF\n)\"")?);
Ok(())
}

#[test]
fn parse_command_sub_with_balanced_single_quotes() -> Result<()> {
assert_ron_snapshot!(test_parse("\"$(cat <<'EOF'\n'hello'\nEOF\n)\"")?);
Ok(())
}

#[test]
fn parse_command_sub_with_balanced_backticks() -> Result<()> {
assert_ron_snapshot!(test_parse("\"$(cat <<'EOF'\n`hello`\nEOF\n)\"")?);
Ok(())
}

#[test]
fn parse_backquoted_command() -> Result<()> {
assert_ron_snapshot!(test_parse("`echo hi`")?);
Expand Down
31 changes: 31 additions & 0 deletions brush-shell/tests/cases/compat/here.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,34 @@ cases:
true
EOF
)

- name: "Here doc with unpaired single quote in command substitution"
stdin: |
echo "$(cat <<'EOF'
it's here
EOF
)"

- name: "Here doc with unpaired backtick in command substitution"
stdin: |
echo "$(cat <<'EOF'
a ` b
EOF
)"

- name: "Here doc with three single quotes in command substitution"
stdin: |
echo "$(cat <<'EOF'
it's Bob's it's
EOF
)"

- name: "Here doc with unpaired single quote in command substitution (#420)"
stdin: |
var=$(
sed 's/nice/cool/' - <<-EOF
that's
"nice"
EOF
)
echo $var
Loading