Skip to content

Commit

Permalink
Merge pull request #104 from akihiro17/prevent-word-splitting
Browse files Browse the repository at this point in the history
quote retuned text values
  • Loading branch information
Ph0enixKM committed May 24, 2024
2 parents 5c8e6da + 8e45979 commit 59ef0c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/modules/function/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ impl SyntaxModule<ParserMetadata> for FunctionInvocation {
impl FunctionInvocation {
fn get_variable(&self, meta: &TranslateMetadata, name: &str, dollar_override: bool) -> String {
let dollar = dollar_override.then_some("$").unwrap_or_else(|| meta.gen_dollar());
let quote = meta.gen_quote();
if matches!(self.kind, Type::Array(_)) {
let quote = meta.gen_quote();
format!("{quote}{dollar}{{{name}[@]}}{quote}")
} else if matches!(self.kind, Type::Text) {
format!("{quote}{dollar}{{{name}}}{quote}")
} else {
format!("{dollar}{name}")
}
Expand Down
8 changes: 7 additions & 1 deletion src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ fn test_std_library() {
loop word in words(\"hello world ciao mondo\") {
echo word
}
// Split a joined string into a list of string
loop word in words(join([\"hello\", \"world\"], \" \")) {
echo word
}
// Join a list of strings into a string
echo join(split(\"hello world\", \"l\"), \"l\")
// Transform string into a lowercase string
Expand Down Expand Up @@ -798,6 +802,8 @@ fn test_std_library() {
"world",
"ciao",
"mondo",
"hello",
"world",
"hello world",
"hello world",
"HELLO WORLD",
Expand Down Expand Up @@ -1120,5 +1126,5 @@ fn variable_ref_function_invocation() {
unsafe foo(a)
echo a
";
test_amber!(code, "sram");
test_amber!(code, "\"sram\"");
}

0 comments on commit 59ef0c6

Please sign in to comment.