Skip to content

HTML API: Add class_list() tests for whitespace and character references - #14300

Closed
sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:html-api/class-list-tests
Closed

sirreal wants to merge 2 commits into
WordPress:trunkfrom
sirreal:html-api/class-list-tests

Conversation

@sirreal

@sirreal sirreal commented Oct 15, 2026

Copy link
Copy Markdown
Member

Adds class_list() tests for how a class attribute value is split and decoded. No existing test passes class_list() or has_class() a class value that starts with whitespace or contains only whitespace, so a change to the loop's leading-whitespace handling, such as #8076, could yield an empty class name without a test failing.

The new cases cover:

  • Splitting: leading, trailing and whitespace-only values; form feed and encoded carriage return separators (a literal CR becomes LF before class_list() reads the value); encoded spaces; vertical tab and no-break space, which are not separators.
  • Character references, using the attribute value rule for legacy names without a semicolon: decoded unless the next character is = or an ASCII alphanumeric. &amp-x gives &-x, &ampx stays &ampx, and &notin stays &notin because only its prefix &not is a legacy name. Also names that require a semicolon, unknown names, and numeric references without a semicolon.

Expected values match jsdom's classList for the same markup. The tests pass on trunk and on #8076; replacing #8076's initial whitespace skip with $at = 0 fails four of them.

This should land before #8076.

Trac ticket: https://core.trac.wordpress.org/ticket/65819

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Choosing cases, writing the tests, checking expected values against jsdom, and drafting this description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…ces.

No test passed class_list() a class value with leading whitespace, only whitespace, a form feed or carriage return separator, or ASCII-like characters that are not separators. No class_list() test covered the attribute-value rules for legacy named character references without a trailing semicolon.

Expected values match jsdom's classList for the same markup.
Cite #59209, which introduced class_list(). Drop the `&not-in` case, which repeats the legacy reference before hyphen case.
@sirreal
sirreal marked this pull request as ready for review October 16, 2026 09:49
@github-actions

Copy link
Copy Markdown

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

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

@lancewillett lancewillett 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.

Reviewed the tests against the implementation and existing coverage, including the unit-tests audit. No blocking findings. The affected classes passed locally in randomized order on single site (585 tests) and multisite (585 tests); PHPCS and current CI pass.

AI review · gpt-6

@lancewillett
lancewillett requested a balanced review from Copilot October 17, 2026 23:09
wporg-sync pushed a commit that referenced this pull request Oct 17, 2026
Check leading and trailing whitespace, whitespace-only values, encoded separators, and character-reference boundaries in `class_list()`. Prevent empty class names and incorrect decoding from passing unnoticed.

Developed in: #14300

Props jonsurrell.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64453 602fd350-edb4-49c9-b593-d223f7449a82

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.

🟢 Approval recommended

The test expectations match HTML attribute parsing rules, and no blocking issues were identified.

No open issues 🎉

What changed in this PR

Adds regression coverage for HTML API class_list() behavior ahead of the loop simplification in #8076.

Changes:

  • Tests whitespace splitting, including encoded separators and non-separating characters.
  • Tests character-reference decoding and duplicate class removal.
File Description
tests/​phpunit/​tests/​html-api/​wpHtmlTagProcessor.php Adds a data-driven test covering class splitting and character references.

Review effort: Balanced

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 17, 2026
Check leading and trailing whitespace, whitespace-only values, encoded separators, and character-reference boundaries in `class_list()`. Prevent empty class names and incorrect decoding from passing unnoticed.

Developed in: WordPress/wordpress-develop#14300

Props jonsurrell.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@64453


git-svn-id: http://core.svn.wordpress.org/trunk@63603 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants