Skip to content

fix(#176): escape \S in the special variable regex - #181

Open
VanshajPoonia wants to merge 1 commit into
joplin:masterfrom
VanshajPoonia:fix/176-special-variable-regex
Open

VanshajPoonia wants to merge 1 commit into
joplin:masterfrom
VanshajPoonia:fix/176-special-variable-regex

Conversation

@VanshajPoonia

@VanshajPoonia VanshajPoonia commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #176

What

Escape the backslash in the pattern wrapInQuotes uses to find special variable lines, so the regex receives \S as intended.

Why

The pattern is built in a template literal, where \S collapses to a literal S. The compiled pattern was ^[^S\n]*template_title[^S\n]*:.*, so "optional whitespace" became "anything except S". A variable such as my_template_title was matched as template_title: that line got quoted, and the real template_title line was left unquoted.

---
my_template_title: text
template_title: {{ my_template_title }}
---

On master this template fails with "template_title should be a string, found object".

The eslint-disable-next-line no-useless-escape above the line was silencing the warning that pointed at this, so it is removed.

Testing

  • New test using the template above. It fails on master with the error quoted above and passes with the change.
  • Full suite passes (102/102), no new lint warnings.
  • Checked in a Joplin desktop dev build from the current dev branch, with the plugin loaded through --dev-plugins: the template above now creates a note titled with the typed value. On master, the same steps show the error quoted above.

AI Assistance Disclosure

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

The pattern is built inside a template literal, where \S collapses to a
literal S. The character class then matched anything except S and a
newline, so a line such as `my_template_title: text` was taken for
`template_title`, and that line got quoted instead of the real one.
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.

preProcessTemplateBody regex: \S in a template literal collapses to a literal S

1 participant