Skip to content

fix: escape values substituted into quoted frontmatter scalars - #1659

Merged
chhoumann merged 5 commits into
masterfrom
fix/1655-quoted-token-escaping
Aug 10, 2026
Merged

fix: escape values substituted into quoted frontmatter scalars#1659
chhoumann merged 5 commits into
masterfrom
fix/1655-quoted-token-escaping

Conversation

@chhoumann

@chhoumann chhoumann commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Investigating #1655: the console warning comes from Obsidian's own YAML parser reading the raw template file - Title: {{VALUE:fileName}} is not valid YAML, so Obsidian complains when it indexes the template. QuickAdd can't suppress that, and the community-suggested workaround (wrap the token in quotes) is the right call. This PR makes the quoted form fully safe and useful:

1. Escaping (cf9cb3e5). QuickAdd substituted the answer verbatim inside the author's quotes, so a value containing the quote character corrupted the created note's frontmatter - Title: "{{VALUE:fileName}}" answered with My "Great" Note wrote Title: "My "Great" Note", which Obsidian cannot parse (the note loses all its properties). VALUE and FIELD substitutions are now escaped when the token exactly spans an author-quoted sole-value scalar: double-quoted scalars get the |type:text escaping rules (\ " and control characters), single-quoted scalars get YAML's ''. Everywhere else (unquoted scalars, partial values like "prefix {{VALUE:x}}", note bodies) the value passes through byte-identical.

2. Explicit |type: consumes the quotes (b354c8a1). A quoted token normally writes a string - and stays that way, so released setups like id: "{{VALUE:id}}" keeping 0042 intact are untouched. But when the token declares |type:number, |type:slider, or |type:checkbox, the declared type wins: the author's quotes are consumed and rating: "{{VALUE:r|type:number}}" writes rating: 42, which Obsidian reads as a Number. So a template can be both warning-free (quoted) and correctly typed. |type:text and |type:multiline declare string semantics and keep their quotes (with escaping).

Verified live in Obsidian 1.13.4 (escaping): a template with Title: "{{VALUE:fileName}}" / author: '{{VALUE:who}}' answered with My "Great" Note / O'Brien creates Title: "My \"Great\" Note" / author: 'O''Brien', and Obsidian reads both properties back as the exact strings. On master the same run produces unparseable frontmatter.

Also adds a docs section to the Template choice page explaining the warning, the quoting recipe, and the |type: interaction.

pnpm test (4872 tests incl. unit + formatter regression coverage for both behaviors), pnpm build-with-lint pass.

Refs #1655

Summary by CodeRabbit

  • Bug Fixes

    • Fixed template token substitutions within quoted YAML frontmatter values.
    • Correctly escaped quotes, backslashes, and control characters according to the surrounding quote style.
    • Preserved typed behavior for number, checkbox, and slider properties.
    • Preserved expected behavior for unquoted values, partial substitutions, array values, and note body content.
  • Documentation

    • Added guidance for using tokens in template frontmatter, including quoting, escaping, and supported property types.

Authors quote tokens in template frontmatter to keep the raw template valid
YAML (Obsidian's parser warns on bare {{...}}, issue #1655). The substituted
value was inserted verbatim, so a value containing the surrounding quote
character corrupted the created note's frontmatter. Escape VALUE and FIELD
substitutions when the token exactly spans an author-quoted sole-value scalar.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@chhoumann, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f5d743f9-d40e-4bce-a825-86b93f6eb788

📥 Commits

Reviewing files that changed from the base of the PR and between 3fcee90 and 97507a3.

📒 Files selected for processing (2)
  • src/formatters/formatter-quoted-scalar.test.ts
  • src/formatters/formatter.ts
📝 Walkthrough

Walkthrough

The formatter now escapes variable and field substitutions inside quoted YAML front-matter scalars. Typed values consume author-provided quotes when required. Tests and documentation cover quoting, control characters, and property types.

Changes

Quoted YAML substitutions

Layer / File(s) Summary
YAML scalar escaping utility
src/utils/yamlScalarQuoting.ts, src/utils/yamlScalarQuoting.test.ts
Adds exact quoted-scalar detection and context-sensitive escaping for double-quoted and single-quoted values. Tests cover control characters, quoted list items, and unchanged contexts.
Formatter integration and guidance
src/formatters/formatter.ts, src/formatters/formatter-quoted-scalar.test.ts, docs/src/content/docs/docs/Choices/TemplateChoice.md
VALUE, FIELD, and FILE replacements use YAML-aware escaping. Number, slider, and checkbox values consume surrounding quotes. Regression tests and documentation cover the resulting behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit checks each YAML quote,
And guards each value as it suits.
Apostrophes pair, backslashes bend,
Typed values shed quotes at the end.
Tokens hop into front matter bright,
And every scalar stays just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: escaping values substituted into quoted frontmatter scalars.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1655-quoted-token-escaping

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploying quickadd with  Cloudflare Pages  Cloudflare Pages

Latest commit: eef133a
Status: ✅  Deploy successful!
Preview URL: https://133f0cf1.quickadd.pages.dev
Branch Preview URL: https://fix-1655-quoted-token-escapi.quickadd.pages.dev

View logs

@chhoumann
chhoumann marked this pull request as ready for review August 10, 2026 05:48

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/formatters/formatter.ts`:
- Around line 1301-1308: The quoted-scalar escaping currently misses anonymous
VALUE substitutions and non-collected array fallbacks for VALUE and FIELD.
Update replaceValueInString and the relevant VALUE/FIELD fallback paths to pass
generated scalar and joined-array text through
escapeValueInsideQuotedYamlScalar, while preserving existing collected
replacement behavior; add regression coverage for both anonymous and
joined-array cases.

In `@src/utils/yamlScalarQuoting.ts`:
- Around line 64-73: The double-quoted scalar escaping in the current function
handles only LF, CR, and tab, leaving other YAML control characters invalid.
Extract or reuse a shared double-quoted YAML escape routine with
quoteYamlDouble, ensuring all control characters are escaped consistently, and
add regression coverage for null, backspace, form feed, escape, and other
remaining control characters.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9d33acb-bf68-4d02-bd54-708d6ef82747

📥 Commits

Reviewing files that changed from the base of the PR and between 4421f93 and cf9cb3e.

📒 Files selected for processing (5)
  • docs/src/content/docs/docs/Choices/TemplateChoice.md
  • src/formatters/formatter-quoted-scalar.test.ts
  • src/formatters/formatter.ts
  • src/utils/yamlScalarQuoting.test.ts
  • src/utils/yamlScalarQuoting.ts

Comment thread src/formatters/formatter.ts Outdated
Comment thread src/utils/yamlScalarQuoting.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf9cb3e546

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/formatters/formatter.ts Outdated
A quoted token normally writes a string, but an explicit |type:number,
|type:slider, or |type:checkbox declares the intended property type: the
author's quotes (there to keep the raw template valid YAML, #1655) are
consumed so Obsidian reads the typed value. |type:text and |type:multiline
keep string semantics and their quotes.
…l control-char coverage

Anonymous {{VALUE}} substitutions and non-collected joined-array fallbacks
(VALUE/FIELD/FILE) now run through the same quoted-scalar escaping as named
tokens, and the double-quoted escape routine is shared with quoteYamlDouble
and covers all C0/DEL control characters.
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