Skip to content

Comments

Incorporate port of CSS.escape() to support funky ID attributes#2397

Merged
westonruter merged 2 commits intotrunkfrom
add/funky-id-support
Feb 20, 2026
Merged

Incorporate port of CSS.escape() to support funky ID attributes#2397
westonruter merged 2 commits intotrunkfrom
add/funky-id-support

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Feb 20, 2026

Summary

This fixes handling of Embeds which have FIGURE elements that have an id attribute containing characters which need escaping to form a valid ID selector in CSS. For example, an HTML ID like a.b.c needs escaping to be a CSS selector as #a\.b\.c.

Important

This fixes an XSS security vulnerability which required an authenticated user with at least a contributor role. Props to @duc193 for responsible disclosure.

Use of AI Tools

Gemini CLI was used to port Mathias Bynens's CSS.escape() polyfill from JS to PHP.

@westonruter westonruter added this to the embed-optimizer n.e.x.t milestone Feb 20, 2026
@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) labels Feb 20, 2026
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.29%. Comparing base (704e37f) to head (a60e5ac).
⚠️ Report is 3 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/embed-optimizer/load.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2397      +/-   ##
==========================================
+ Coverage   69.17%   69.29%   +0.11%     
==========================================
  Files          90       90              
  Lines        7708     7737      +29     
==========================================
+ Hits         5332     5361      +29     
  Misses       2376     2376              
Flag Coverage Δ
multisite 69.29% <96.77%> (+0.11%) ⬆️
single 35.63% <93.54%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

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 adds CSS identifier escaping to properly handle embed FIGURE elements with special characters in their ID attributes. The implementation ports the JavaScript CSS.escape() polyfill by Mathias Bynens to PHP, ensuring that special characters in HTML IDs (like dots, brackets, colons) are properly escaped when used in CSS selectors.

Changes:

  • Added escape_css() private method to properly escape CSS identifiers according to CSSOM spec
  • Added comprehensive unit tests for the escape function covering edge cases
  • Added integration test demonstrating proper escaping of IDs with brackets, dots, and colons

Reviewed changes

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

Show a summary per file
File Description
plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php Implements the escape_css() method and integrates it into the CSS selector generation for embed elements
plugins/embed-optimizer/tests/test-class-embed-optimizer-tag-visitor-escape-css.php Comprehensive unit tests for the escape_css() method covering empty strings, special characters, control characters, unicode, and complex identifiers
plugins/embed-optimizer/tests/test-cases/figures-with-fancy-ids/set-up.php Test setup file defining URL metrics for three test figures with special ID attributes
plugins/embed-optimizer/tests/test-cases/figures-with-fancy-ids/expected.html Expected HTML output showing proper CSS escaping in generated style rules for IDs containing brackets, dots, and colons
plugins/embed-optimizer/tests/test-cases/figures-with-fancy-ids/buffer.html Input HTML for integration test with three figure elements having IDs with special characters

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

@westonruter westonruter merged commit 9260fcf into trunk Feb 20, 2026
23 checks passed
@westonruter westonruter deleted the add/funky-id-support branch February 20, 2026 19:36
@westonruter westonruter removed this from the embed-optimizer n.e.x.t milestone Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant