php / php/php-src

get_html_translation_table() inconsistent results with ENT_XHTML?

Open
#11,527 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

print_r(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES | ENT_SUBSTITUTE | ENT_XHTML, "UTF-8"));
print_r(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_SUBSTITUTE | ENT_XHTML, "UTF-8"));

Resulted in this output:

Array
(
    ["] => &quot;
    [&] => &amp;
    ['] => &apos;
    [<] => &lt;
    [>] => &gt;
)
Array
(
    ["] => &quot;
    [&] => &amp;
    ['] => &#039;
    [<] => &lt;
    [>] => &gt;
    [ ] => &nbsp;
    // ...
    // ...
)

But I expected the specialchars table to be a subset of the entities table. The single quotes in the entities table is substituted using the decimal notation, while it uses the html5 named entity notation in the specialchars table.

PHP Version

PHP 5.4 to PHP 8.2

Operating System

mint/ubuntu 22.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the get_html_translation_table() calls from the issue on a supported PHP build, comparing HTML_SPECIALCHARS and HTML_ENTITIES with ENT_XHTML. Trace the implementation and existing tests for these flags; done means the specialchars table has consistent quote mappings with the entities table, including the single-quote representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.