Skip to content

fix(#177): quote special variable values that contain double quotes - #182

Open
VanshajPoonia wants to merge 1 commit into
joplin:masterfrom
VanshajPoonia:fix/177-quote-special-variables
Open

VanshajPoonia wants to merge 1 commit into
joplin:masterfrom
VanshajPoonia:fix/177-quote-special-variables

Conversation

@VanshajPoonia

@VanshajPoonia VanshajPoonia commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #177
Fixes #156

What

wrapInQuotes now skips a value only when it starts with a quote, as suggested in the issue. When it wraps a value, it escapes backslashes and double quotes so YAML reads the value back exactly as written.

Why

The old check skipped any value containing ", so a value like {{ datetime format="dddd D MMMM YYYY" }} was left unquoted and YAML failed on the leading {. That is the "There was an error parsing this template" reported in #156.

Once those values are wrapped, escaping is needed: an unescaped " would end the YAML string early, and backslashes inside double quotes are YAML escape sequences.

Behaviour changes

  • Values that contain " but don't start with a quote are now wrapped. Before, they were parsed as plain YAML scalars, which worked unless they started with {. The parsed value is the same.
  • Backslashes in special variable values are now always kept as written. Before, values without a " were wrapped unescaped, so YAML read backslashes as escapes: \t became a tab and \Q failed to parse.
  • Values the user quoted themselves are left untouched, as before.

Testing

  • New test with double quotes inside helper arguments in template_title, template_tags and template_todo_alarm. It fails on master with the YAMLException from Error when parsing date #156 and passes with the change.
  • New test that pins two cases that already worked: a value with a backslash and inner double quotes, and a value the user wrapped in single quotes. Removing the backslash escaping makes it fail.
  • The exact template from Error when parsing date #156 now parses. (Its second, unbracketed de is read by moment as date tokens, which is down to the format string.)
  • Full suite passes (103/103), no new lint warnings.
  • Checked in a Joplin desktop dev build from the current dev branch, with the plugin loaded through --dev-plugins: a template with template_title: {{ datetime format="dddd D MMMM YYYY" }} and template_tags: {{ datetime format="YYYY" }}, weekly now creates the note with the expected title and tags. On master, it shows the YAMLException.
  • Merges cleanly with fix: stop html-escaping template output #174 and Fix variables form dialog resize glitch for templates with many variables #179, which also touch src/parser.ts.

AI Assistance Disclosure

I used an AI coding assistant to investigate the issue, write the fix and the tests, and draft this description. The tests and lint pass locally, and the fix was checked end to end in a Joplin desktop dev build.

…otes

wrapInQuotes skipped any value containing a double quote, assuming the
user had quoted it. Values whose quotes sit inside a helper argument,
such as {{ datetime format="YYYY" }}, were then left unquoted and the
frontmatter failed to parse.

Only skip values that start with a quote, and escape backslashes and
double quotes when wrapping so the value comes out as written.
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.

wrapInQuotes skips values containing a double quote, so helper arguments break frontmatter parsing Error when parsing date

1 participant