Repository navigation
Conversation
Templates render into markdown notes, not html, but both Handlebars
compile calls used the default options, so every {{variable}} was run
through escapeExpression. A value containing an apostrophe came out as
' in the generated note, and the only workaround was the triple
stache {{{variable}}}, which most users never find.
Pass noEscape to both compile sites:
- parseSpecialVariables, which covers all four special variables, so
template_title and template_tags stop mangling values too
- the note body itself
The variable-name validity probe is left alone, since its output is
discarded.
The test covers the double and triple stache side by side, so the
existing {{{variable}}} behaviour is pinned as unchanged rather than
assumed.
Fixes joplin#173
|
Verified against a dev build in the app, not just in jest. A template variable containing Dropdown ( |
|
@nishantwrp mind taking a look at this one? Small diff, but it changes rendering for every existing template, so I'd rather not merge on my own verification alone. |
nishantwrp
left a comment
There was a problem hiding this comment.
My only concern is if people use html tags for format their notes (tables, etc.). Maybe make it a template level setting?
|
Thanks @nishantwrp. Literal markup isn't affected, Handlebars only escapes the output of The real change is that angle brackets in a value now reach the renderer raw, so a typed |
Fixes #173
What
Pass
{ noEscape: true }to bothHandlebars.compile()calls insrc/parser.ts, so template output is no longer HTML-escaped.Why
Characters like
',",&and<typed into a template variable came out as HTML entities in the generated note.it's a "test"becameit's a "test".Both compile calls used the default options, so every
{{ variable }}ran throughescapeExpression. That is right for an HTML target, but templates render into markdown notes. The note looks fine in the viewer because Joplin's renderer passes entities through, so the damage only surfaces when you edit, search, export or sync the note.The only workaround was the triple stache,
{{{ variable }}}, which is not discoverable and should not be needed for ordinary text.How
noEscapeon both sites:parseTemplateparseSpecialVariables, so the problem stops reaching the note title as well as its bodyThis covers all four special variables, not just the two in the test.
template_notebookis a folder ID andtemplate_todo_alarma date string, andgetNoteMetadatathrows on an unparseable value for either, so the existing tests for those still hold.The variable-name validity probe is left alone, since its output is discarded.
Back-compat.
{{{ variable }}}behaves identically undernoEscape. The test renders the double and triple stache side by side and expects the same output from both, so that is pinned rather than assumed. No existing test covered the old escaping behaviour, so nothing was relying on it.Testing. The new test goes red against master with the exact reported symptom and green with the change. Full suite 99/99, lint clean. Also verified against a dev build in the app, including dropdown variables (see the comment below).
One thing a reviewer may ask.
wrapInQuotesstill quotestemplate_titlein the frontmatter while its value is no longer escaped. Those are different stages and do not interact. That function has two separate defects of its own, now filed as #176 and #177 rather than widening this PR.