Skip to content

fix: HTML-encode single quote character (issue #546)#618

Merged
rexm merged 2 commits into
masterfrom
worktree-agent-a732b233a2e1bed2c
Jun 20, 2026
Merged

fix: HTML-encode single quote character (issue #546)#618
rexm merged 2 commits into
masterfrom
worktree-agent-a732b233a2e1bed2c

Conversation

@rexm

@rexm rexm commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #546

  • The default TextEncoder in HandlebarsConfiguration was HtmlEncoderLegacy, which deliberately omitted encoding of ', `, and =.
  • Changed the default to HtmlEncoder, which encodes all 7 characters (&, <, >, ", ', `, =) matching handlebars.js behavior.
  • HtmlEncoderLegacy remains available for users who need the old behavior — set HandlebarsConfiguration.TextEncoder = new HtmlEncoderLegacy() to opt in.

Changes

  • source/Handlebars/Configuration/HandlebarsConfiguration.cs: Change default TextEncoder from HtmlEncoderLegacy to HtmlEncoder
  • source/Handlebars.Test/IssueTests.cs: Add Issue546_SingleQuoteIsHtmlEncoded and Issue546_HtmlSpecialCharsAreEncoded tests
  • source/Handlebars.Test/HandlebarsSpecCoverageTests.cs: Update spec-gap tests to reflect the now-closed gap; add legacy-encoder variant tests

Test plan

  • New Issue546_SingleQuoteIsHtmlEncoded test confirms single quotes are encoded as &#x27;
  • New Issue546_HtmlSpecialCharsAreEncoded theory covers all 7 special characters
  • All 1754 existing tests pass
  • HtmlEncoderTests and HtmlEncoderLegacyTests unchanged and still passing

🤖 Generated with Claude Code

rexm and others added 2 commits June 19, 2026 20:53
Switch the default TextEncoder from HtmlEncoderLegacy to HtmlEncoder so
that single quotes ('), backticks (`), and equals signs (=) are HTML-encoded
as &#x27;, &#x60;, and &#x3D; respectively — matching handlebars.js behavior.
Users who require the old unescaped behavior can opt in explicitly via
HandlebarsConfiguration.TextEncoder = new HtmlEncoderLegacy().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rexm rexm enabled auto-merge June 20, 2026 17:05
@sonarqubecloud

Copy link
Copy Markdown

@rexm rexm merged commit af3b085 into master Jun 20, 2026
7 checks passed
@rexm rexm deleted the worktree-agent-a732b233a2e1bed2c branch June 20, 2026 17:17
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.

handlebars not escape ' character

1 participant