Skip to content

Stop truncating legacy entity names in the named character reference table - #288

Open
whoalin1 wants to merge 1 commit into
Masterminds:masterfrom
whoalin1:fix/legacy-entity-name-truncation
Open

whoalin1 wants to merge 1 commit into
Masterminds:masterfrom
whoalin1:fix/legacy-entity-name-truncation

Conversation

@whoalin1

@whoalin1 whoalin1 commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes the named character reference table part of #286 (the ≖, ⊚, ⩝, ∥ and ⊃ cases). The numeric reference, semicolon-less reference and tag-name parts of that issue are not addressed here.

Root cause: entities.json lists each legacy entity twice, as ê and as &ecirc (no semicolon). bin/entities.php stripped the first and last character from every key (substr($name, 1, -1)). That is right for ê, but &ecirc became ecir. These fake names overwrote the real WHATWG entities that share the prefix:

name before expected
ecir ê (U+00EA) ≖ (U+2256)
ocir ô (U+00F4) ⊚ (U+229A)
ord º (U+00BA) ⩝ (U+2A5D)
par (U+00B6) ∥ (U+2225)
sup ³ (U+00B3) ⊃ (U+2283)

The bug also added 97 names that do not exist (Aacut, am, cop, brvba, ...). For example, &Aacut; decoded to Á, but per spec it should stay literal.

Fix:

  • bin/entities.php now only keeps keys ending in ;. The tokenizer always requires the ;, and every semicolon-less legacy name is also listed with one, so nothing valid is lost.
  • src/HTML5/Entities.php gets the same result: the 97 truncated keys are removed and the 5 values above are corrected. I edited the existing file in place instead of re-running the script, which fetches from the network, so the formatting stays the same.

I compared the result with the WHATWG table (Python's html.entities.html5, semicolon names only). All 2125 names match and there are no extra keys.

Validation (PHP 8.5, composer:2 Docker image):

  • vendor/bin/phpunit: 176 tests OK. The new CharacterReferenceTest::testLookupNameDoesNotTruncateLegacyNames fails on master ('≖' expected, 'ê' actual) and passes with this change.
  • With loadHTML('<body>…</body>'), &ecir; gives ≖, &ocir; gives ⊚, &sup; gives ⊃, &Aacute; gives Á, and &Aacut; stays literal.
  • I did not run php-cs-fixer 2.19 (the CS workflow downloads the phar). The changes only remove or edit table lines and add a test method in the existing style.

…table

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

1 participant