Skip to content

Commit

Permalink
fix: string replacement with slashes (#231)
Browse files Browse the repository at this point in the history
Fixes the case where a string replacement contains / chars, e.g.:
    ${value/pattern/some/replacement}
  • Loading branch information
reubeno authored Oct 24, 2024
1 parent 095a4be commit ade6fbb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion brush-parser/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ peg::parser! {
s:$(arithmetic_word(<[':' | '}']>)) { ast::UnexpandedArithmeticExpr { value: s.to_owned() } }

rule parameter_replacement_str() -> String =
"/" s:$(word(<['}' | '/']>)) { s.to_owned() }
"/" s:$(word(<['}']>)) { s.to_owned() }

rule parameter_search_pattern() -> String =
s:$(word(<['}' | '/']>)) { s.to_owned() }
Expand Down
1 change: 0 additions & 1 deletion brush-shell/tests/cases/arrays.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ cases:
echo ${x[${x[0]}]}
- name: "Append array-resulting expansion to array"
skip: true # Need to asses on different bash versions
stdin: |
declare -a otherarray=("a" "b" "c")
declare -a ourarray=()
Expand Down
5 changes: 5 additions & 0 deletions brush-shell/tests/cases/word_expansion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ cases:
echo "\${arr[@]/world/WORLD}: ${arr[@]/world/WORLD}"
echo "\${arr[*]/world/WORLD}: ${arr[*]/world/WORLD}"
- name: "Substring replacement with slashes"
stdin: |
var="Hello, world!"
echo "\${var/world//world}: ${var/world//world}"
- name: "Prefix substring replacement"
stdin: |
var="Hello, world!"
Expand Down

0 comments on commit ade6fbb

Please sign in to comment.