Skip to content

Add HTML string escape and unescape APIs#13408

Draft
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:html-escape-api
Draft

Add HTML string escape and unescape APIs#13408
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:html-escape-api

Conversation

@bneradt

@bneradt bneradt commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This adds reusable core HTML escaping and unescaping helpers and the
TSStringHtmlEscape and TSStringHtmlUnescape plugin APIs. The escaping
behavior follows the WHATWG fragment serialization algorithm:
https://html.spec.whatwg.org/#escapingString

Fixes: #13331

@bneradt bneradt added this to the 11.0.0 milestone Jul 20, 2026
@bneradt bneradt self-assigned this Jul 20, 2026
@bneradt bneradt changed the title Add HTML string escaping API TSStringHtmlEscape: Add HTML string escaping API Jul 20, 2026
@bneradt
bneradt requested review from Copilot and ezelkow1 July 20, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a reusable HTML escaping implementation in tscore and exposes it to plugins via the new TSStringHtmlEscape TSAPI function, with unit + gold-test coverage and API documentation (per #13331).

Changes:

  • Add Encoding::html_escape() core implementation and Catch2 unit tests.
  • Add new public plugin API TSStringHtmlEscape() and document it.
  • Add a gold-test plugin + replay test verifying escaping in a response transform.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/gold_tests/pluginTest/tsapi/test_TSStringHtmlEscape.test.py Adds an ATS replay-based gold test driver that deploys the new test plugin.
tests/gold_tests/pluginTest/tsapi/test_TSStringHtmlEscape.replay.yaml Defines replay transactions validating response-body escaping behavior end-to-end.
tests/gold_tests/pluginTest/tsapi/test_TSStringHtmlEscape.cc Implements a response-transform test plugin that calls TSStringHtmlEscape().
tests/gold_tests/pluginTest/tsapi/CMakeLists.txt Builds the new autest plugin.
src/tscore/unit_tests/test_Encoding.cc Adds Catch2 coverage for Encoding::html_escape() behavior and error handling.
src/tscore/Encoding.cc Implements Encoding::html_escape() and associated helpers.
src/api/InkAPI.cc Adds the TSStringHtmlEscape() TSAPI wrapper calling into Encoding::html_escape().
include/tscore/Encoding.h Exposes the new Encoding::html_escape() declaration.
include/ts/ts.h Adds the TSStringHtmlEscape() API declaration (and a new mode constant).
doc/developer-guide/api/functions/TSStringHtmlEscape.en.rst Documents the new TSAPI function and usage guidance.

Comment thread include/ts/ts.h Outdated
Comment thread src/tscore/unit_tests/test_Encoding.cc
@bneradt
bneradt force-pushed the html-escape-api branch 3 times, most recently from eab989c to 72f8da9 Compare July 20, 2026 16:48
@bneradt bneradt changed the title TSStringHtmlEscape: Add HTML string escaping API Add HTML string escape and unescape APIs Jul 20, 2026
@bneradt
bneradt force-pushed the html-escape-api branch 2 times, most recently from bff922d to ad1da66 Compare July 20, 2026 17:11
ATS does not provide reusable HTML escaping helpers to core
components or plugins.

This adds paired escape and unescape helpers, exposes them through
the plugin API, and covers both directions with unit and replay
tests. Escaping follows the WHATWG fragment serialization algorithm.

Fixes: apache#13331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Library-ized html escaper

2 participants