Skip to content

fix(config): parse unquoted special-char values in YAML flow collections - #2761

Merged
AucaCoyan merged 5 commits into
espanso:devfrom
YuriNachos:YuriNachos/w3-espanso
Sep 1, 2026
Merged

AucaCoyan merged 5 commits into
espanso:devfrom
YuriNachos:YuriNachos/w3-espanso

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

Fixes #2748.

Root cause

PR #2532 swapped serde_yaml 0.8 → serde_norway (libyaml-based, strict). A plain (unquoted) scalar inside a flow collection ([...] / {...}) must not begin with a flow-indicator character (:, >, |); serde_yaml tolerated these, so configs that parsed before 2.4.0 — e.g. triggers: [:->,:>-] or word_separators: [:>-] — now fail with "did not find expected node content ... while parsing a flow node".

Fix

New parse_lenient parses strictly first; only on failure does it retry on a leniently re-quoted copy (lenient_flow_quote), which single-quotes bare flow-collection scalars that begin with :, >, or |. The retry-on-failure gate is the central safety property: every config that parses today is returned byte-for-byte untouched, and if the retry still fails the original error is returned — so genuinely malformed YAML fails exactly as before. Already-quoted scalars and # comments are skipped verbatim; feature/reserved indicators (* ! & @ %) are deliberately left strict (pre-2.4.0 did not accept them either).

Wired into both YAML entry points: config/parse/yaml.rs and matches/group/loader/yaml/parse.rs.

Test plan

  • cargo fmt --all -- --check — clean
  • cargo clippy -p espanso-config --all-targets -- --deny warnings — clean
  • cargo test -p espanso-config — 95 passed, 0 failed, including: the v2.4.0 doesn't parse unquoted values in - triggers: #2748 reproducer (:->, :>-, :-), :>hello), a zero-regression corpus of real espanso match/config shapes (proven value-identical strict vs lenient), and pathological-input robustness (unterminated quotes, NUL, 100k-deep nesting — all terminate).

@YuriNachos
YuriNachos requested a review from AucaCoyan as a code owner August 8, 2026 16:18
Restore the pre-2.4.0 (serde_yaml) tolerance for unquoted flow-collection
values that start with a YAML flow indicator (`:`, `>`, `|`), e.g.
`triggers: [:->,:>-]`, which PR espanso#2532 (serde_yaml -> serde_norway) broke.
serde_norway is libyaml-based and rejects such scalars with
"did not find expected node content ... while parsing a flow node".

Add a pure `lenient_flow_quote` helper applied only on retry-on-failure: the
strict parse is tried first, so every config that parses today is returned
byte-for-byte untouched. The fix covers both YAMLMatchGroup and YAMLConfig
parse entry points via a shared `parse_lenient<T>` wrapper in `util`.

`|`/`>` block-scalar bodies (e.g. a multi-line `replace: |` whose literal
text contains `[ ... ]`) are detected and copied verbatim, so the transform
never re-quotes inside them.

Fixes espanso#2748

Co-Authored-By: Claude <[email protected]>
@YuriNachos
YuriNachos force-pushed the YuriNachos/w3-espanso branch from 76516a8 to 73f6098 Compare August 8, 2026 16:49
@YuriNachos

Copy link
Copy Markdown
Contributor Author

Updated to fix a defect a post-publish adversarial review found.

Before: lenient_flow_quote re-quoted inside | / > block-scalar bodies. With a config that combined a #2748 trigger and a replace: | whose literal body contained flow-like text, the body was silently corrupted — e.g. if [ :>x ]; then echo hi; fi became if [ ':>x' ]; then echo hi; fi (broken shell command). That is a worse failure mode than the 2.4.0 regression this PR fixes.

Now: the transform detects | / > block-scalar headers in block context (depth == 0) and copies the whole block — header + body — verbatim, so literal text in a block scalar is never mistaken for YAML flow structure. Detection is deliberately liberal (a false positive only misses a fix in that block; a false negative could corrupt data). Added a regression test combining the #2748 trigger with a replace: | body containing [ :>x ], asserting the body is byte-identical.

cargo test -p espanso-config — 97 passed, 0 failed (was 95). Code change confined to espanso-config/src/util.rs (+ the test in parse.rs); the strict-first / retry-on-failure / original-error-preserved safety properties are unchanged.

@YuriNachos

Copy link
Copy Markdown
Contributor Author

Since this one repairs the 2.4.0 flow-collection parsing regression from the serde_norway swap (#2748), I'd appreciate a sanity check on the approach: the config is still parsed strictly first, and the leniently re-quoted retry only runs when that strict parse fails. Would you be open to reviewing it as-is, or is there a different layering or additional regression cases you'd want covered first? I'm glad to prioritise whatever would help it move forward.

@AucaCoyan
AucaCoyan merged commit 2648664 into espanso:dev Sep 1, 2026
4 checks passed
@AucaCoyan

Copy link
Copy Markdown
Collaborator

Thank you so much!

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.

v2.4.0 doesn't parse unquoted values in - triggers:

2 participants