Skip to content

fix(config): Keep template spans intact in command strings - #878

Open
JeanMertz wants to merge 2 commits into
mainfrom
plugin-prompt-channel
Open

fix(config): Keep template spans intact in command strings#878
JeanMertz wants to merge 2 commits into
mainfrom
plugin-prompt-channel

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

Command strings written as plain strings (rather than the structured program/args form) are split into shell words before minijinja renders any {{ }}, {% %}, or {# #} spans. Until now that split used shlex::split directly, so a template expression containing spaces was torn across multiple arguments, e.g. just x {{ a | default('') }} produced args: ["x", "{{", "a", "|", "default('')", "}}"] instead of a single argument.

Template spans are now masked with NUL-delimited placeholders before the shell split and restored afterwards, so a span survives as one argument even when it contains spaces or quoted filter arguments. String literals inside expression/statement spans are tracked so a }}/%} inside a quoted string does not end the span early, and an unterminated span is kept whole rather than mangled, leaving the error to minijinja at render time. Quotes inside a span (e.g. inside a {# comment #}) no longer trip the unbalanced-shell-quoting check.

This only affects the string form of CommandConfigOrString; the structured program/args form is unaffected.

Command strings written as plain strings (rather than the structured
`program`/`args` form) are split into shell words before minijinja
renders any `{{ }}`, `{% %}`, or `{# #}` spans. Until now that split
used `shlex::split` directly, so a template expression containing
spaces was torn across multiple arguments, e.g. `just x {{ a |
default('') }}` produced `args: ["x", "{{", "a", "|", "default('')",
"}}"]` instead of a single argument.

Template spans are now masked with NUL-delimited placeholders before
the shell split and restored afterwards, so a span survives as one
argument even when it contains spaces or quoted filter arguments.
String literals inside expression/statement spans are tracked so a
`}}`/`%}` inside a quoted string does not end the span early, and an
unterminated span is kept whole rather than mangled, leaving the
error to minijinja at render time. Quotes inside a span (e.g. inside
a `{# comment #}`) no longer trip the unbalanced-shell-quoting check.

This only affects the string form of `CommandConfigOrString`; the
structured `program`/`args` form is unaffected.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant