Skip to content

i18n: Escape decoded HTML attributes - #862

Merged
MaggieCabrera merged 4 commits into
trunkfrom
codex/i18n-escape-decoded-attributes
Sep 29, 2026
Merged

MaggieCabrera merged 4 commits into
trunkfrom
codex/i18n-escape-decoded-attributes

Conversation

@MaggieCabrera

Copy link
Copy Markdown
Contributor

Summary

Escape HTML attribute values after token processing during localized export.

This preserves encoded quotes and backslashes after the HTML processor decodes attribute values.

Test plan

  • vendor/bin/phpunit -c phpunit.xml.dist --verbose --group locale
  • vendor/bin/phpunit -c phpunit.xml.dist --verbose --filter 'CBT_Theme_Locale_EscapeTextContent|test_token_processor'
  • vendor/bin/phpcs --standard=phpcs.xml.dist includes/create-theme/theme-locale.php includes/create-theme/theme-token-processor.php tests/CbtThemeLocale/escapeTextContent.php
  • Confirmed encoded attribute values remain inert and generated pattern PHP stays parse-clean.

@MaggieCabrera MaggieCabrera self-assigned this Aug 20, 2026

@mikachan mikachan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like this introduces a regression, as attribute names are no longer being escaped.

As the blanket pre-escape has been removed, that means values are now escaped individually but names aren't, in any of the four branches of process_attribute().

We should be able to fix this by adding this to the top of process_attribute() (which should fix all branches):

private function process_attribute( $attr_name, $attr_value ) {
      $token_part = '';
      $attr_name  = $this->escape_php_single_quoted_string( $attr_name );

* @param string $value The value to escape.
* @return string The escaped value.
*/
private function escape_php_single_quoted_string( $value ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function is now duplicated in here and theme-locale.php. Is it worth extracting this to a single shared function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 9409868

Escape tag names and attribute names before they are embedded in
generated PHP strings, since the blanket pre-escape no longer covers
them. Move escape_php_single_quoted_string() to CBT_Theme_Utils so the
locale and token processor classes share one implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaggieCabrera

Copy link
Copy Markdown
Contributor Author

CIs are red, but a fix for that is in #877

@mikachan mikachan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the changes, these look good! We should probably rebase once #877 has landed, so we can see the CI passing.

@MaggieCabrera
MaggieCabrera merged commit 7b150d1 into trunk Sep 29, 2026
13 checks passed
@MaggieCabrera
MaggieCabrera deleted the codex/i18n-escape-decoded-attributes branch September 29, 2026 14:21
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.

2 participants