Skip to content

fix: avoid double-decoding dialog selection in getUserTemplateSelection - #180

Merged
alondmnt merged 1 commit into
joplin:masterfrom
sh1vam31:fix/remove-double-decode-template-selection_#178
Oct 3, 2026
Merged

alondmnt merged 1 commit into
joplin:masterfrom
sh1vam31:fix/remove-double-decode-template-selection_#178

Conversation

@sh1vam31

Copy link
Copy Markdown
Contributor

Fixes #178

When selecting a template from the template selection dialog, getUserTemplateSelection was calling decode() on the value returned from formData. Since Chromium automatically decodes HTML entity values upon form submission, this resulted in double-decoding, corrupting titles or content containing literal HTML entities (e.g. Q&A Template became Q&A Template).

Fix

src/utils/templates.ts

  • Removed the redundant decode() call in getUserTemplateSelection(), returning templateValue || null directly from formData
  • Removed unused decode import from html-entities

tests/utils/templates.spec.ts

  • Updated existing mock unit test cases to supply unencoded strings matching real browser DOM behavior
  • Added a unit test (should not double-decode template value containing literal HTML entities (#178)) verifying that literal entities like Q&A Template are preserved without double-decoding

Testing

  1. Created a template note titled Q&A Template tagged as template
  2. Clicked Tools → Templates → Create note from template
  3. Selected Q&A Template and clicked Select
  4. Verified that the created note preserved the exact title Q&A Template instead of being corrupted to Q&A Template
  5. Verified all unit tests pass cleanly (npm test)

@sh1vam31

Copy link
Copy Markdown
Contributor Author

Hey @alondmnt @nishantwrp,

I've opened this PR to resolve issue #178. The redundant decode() call in getUserTemplateSelection was causing double-decoding for note titles with HTML entities.

All unit tests are passing cleanly. Could you please review when you have a moment?

And let me know if any improvements or adjustments are needed.

@alondmnt

alondmnt commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thank you @sh1vam31!

@alondmnt
alondmnt merged commit 9ce8016 into joplin:master Oct 3, 2026
3 checks passed
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.

getUserTemplateSelection double-decodes the dialog value

2 participants