Add shell escaping for arrays of text
This commit is contained in:
parent
62745cda95
commit
b432fc82c7
@ -304,6 +304,7 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
{"by_line", "Shell$by_line", "func(command:Shell)->(func()->Text?)?"},
|
||||
{"escape_int", "Int$value_as_text", "func(i:Int)->Shell"},
|
||||
{"escape_text", "Shell$escape_text", "func(text:Text)->Shell"},
|
||||
{"escape_text_array", "Shell$escape_text_array", "func(texts:[Text])->Shell"},
|
||||
{"run_bytes", "Shell$run", "func(command:Shell)->[Byte]?"},
|
||||
{"run", "Shell$run", "func(command:Shell)->Text?"},
|
||||
)},
|
||||
|
@ -33,6 +33,17 @@ public Shell_t Shell$escape_text(Text_t text)
|
||||
return (Text_t){.length=shell_graphemes.length, .tag=TEXT_GRAPHEMES, .graphemes=shell_graphemes.data};
|
||||
}
|
||||
|
||||
public Shell_t Shell$escape_text_array(Array_t texts)
|
||||
{
|
||||
Array_t all_escaped = {};
|
||||
for (int64_t i = 0; i < texts.length; i++) {
|
||||
Text_t raw = *(Text_t*)(texts.data + i*texts.stride);
|
||||
Text_t escaped = Shell$escape_text(raw);
|
||||
Array$insert(&all_escaped, &escaped, I(0), sizeof(Text_t));
|
||||
}
|
||||
return Text$join(Text(" "), all_escaped);
|
||||
}
|
||||
|
||||
public OptionalArray_t Shell$run_bytes(Shell_t command)
|
||||
{
|
||||
const char *cmd_str = Text$as_c_string(command);
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
OptionalClosure_t Shell$by_line(Shell_t command);
|
||||
Shell_t Shell$escape_text(Text_t text);
|
||||
Shell_t Shell$escape_text_array(Array_t texts);
|
||||
OptionalArray_t Shell$run_bytes(Shell_t command);
|
||||
OptionalText_t Shell$run(Shell_t command);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user