Skip to content

Allow SVG dominant-baseline and text-orientation presentation attributes - #1526

Merged
cure53 merged 1 commit into
cure53:mainfrom
Develop-KIM:fix/svg-text-adaption-attrs
Jul 11, 2026
Merged

Allow SVG dominant-baseline and text-orientation presentation attributes#1526
cure53 merged 1 commit into
cure53:mainfrom
Develop-KIM:fix/svg-text-adaption-attrs

Conversation

@Develop-KIM

Copy link
Copy Markdown
Contributor

Fixes #1525.

dominant-baseline was missing from the SVG attribute allow-list, so DOMPurify stripped it (e.g. <text dominant-baseline="middle">), even though its baseline siblings alignment-baseline and baseline-shift are already allowed. This adds it, plus text-orientation from the same W3C SVG2 text property adaptions group. Both are enum-only presentation attributes with no script or URL surface.

Before / after (default config):

IN : <svg><text dominant-baseline="middle">x</text></svg>
OUT: <svg><text>x</text></svg>            // before
OUT: <svg><text dominant-baseline="middle">x</text></svg>   // after

You mentioned being happy to add a few safe ones in bulk. I checked the rest of that spec section and deliberately left out unicode-bidi (its bidi-override value is a text-reordering/spoofing surface, so it felt like your call) and the deprecated glyph-orientation-horizontal / glyph-orientation-vertical. Happy to add any of those if you'd like.

Added two regression fixtures to test/fixtures/expect.mjs. Lint and the jsdom suite pass locally.

Implemented with AI assistance; I've reviewed and verified every change.

Copilot AI review requested due to automatic review settings July 10, 2026 01:06
@Develop-KIM
Develop-KIM requested a review from x00mario as a code owner July 10, 2026 01:06

Copilot AI left a comment

Copy link
Copy Markdown

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 updates DOMPurify’s SVG attribute allow-list to preserve two safe SVG2 text presentation attributes (dominant-baseline and text-orientation) that were previously stripped, and adds regression fixtures to prevent regressions.

Changes:

  • Add dominant-baseline and text-orientation to the SVG allowed attributes list (src/attrs.ts).
  • Add two regression fixtures covering both attributes (test/fixtures/expect.mjs).
  • Regenerate distribution bundles (dist/*) to reflect the updated allow-list.

Reviewed changes

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

Show a summary per file
File Description
test/fixtures/expect.mjs Adds regression fixtures ensuring the two SVG attributes are preserved.
src/attrs.ts Extends the SVG attribute allow-list with dominant-baseline and text-orientation.
dist/purify.js Rebuilt distribution bundle incorporating the updated SVG allow-list.
dist/purify.es.mjs Rebuilt ESM distribution bundle incorporating the updated SVG allow-list.
dist/purify.cjs.js Rebuilt CJS distribution bundle incorporating the updated SVG allow-list.
dist/purify.min.js Rebuilt minified distribution bundle incorporating the updated SVG allow-list.
dist/purify.min.js.map Updated sourcemap corresponding to the rebuilt minified bundle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cure53

cure53 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Excellent, thank you 🙂

@cure53

cure53 commented Jul 10, 2026

Copy link
Copy Markdown
Owner

The changes look good, thanks @Develop-KIM .

Would you mind adding signatures to your commit? Then we can merge.

Both are pure presentation attributes from the W3C SVG2 text property
adaptions but were missing from the SVG attribute allow-list, so
DOMPurify stripped e.g. <text dominant-baseline="middle">. Their
baseline siblings alignment-baseline and baseline-shift are already
allow-listed; both added attributes are enum-only with no script/URL
surface.

Fixes #1525

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Develop-KIM
Develop-KIM force-pushed the fix/svg-text-adaption-attrs branch from 7c54eb9 to fcc22c6 Compare July 10, 2026 16:01
@Develop-KIM

Copy link
Copy Markdown
Contributor Author

Signed the commit, thanks

@cure53

cure53 commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Super, thank you!

@cure53
cure53 merged commit 54cb709 into cure53:main Jul 11, 2026
12 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.

SVG attribute dominant-baseline gets removed

4 participants