Req #77769 [Opn]: html_entity_decode does not decode all HTML5 entities
Edit report at https://bugs.php.net/bug.php?id=77769&edit=1
ID: 77769
Updated by: requinix@php.net
Reported by: cananian at wikimedia dot org
Summary: html_entity_decode does not decode all HTML5
entities
Status: Open
Type: Feature/Change Request
Package: Strings related
Operating System: n/a
PHP Version: 7.3.3
Block user comment: N
Private report: N
New Comment:
They are decoded for graceful handling. &foo is still a parse error.
Previous Comments:
------------------------------------------------------------------------
[2019-03-19 20:10:11] cananian at wikimedia dot org
Description:
------------
The latest HTML5 specs contain a number of "semicolon-less" entities which are decoded in
most circumstances. See the list at https://html.spec.whatwg.org/#named-character-references
(just the ones which don't end in a semicolon).
These are decoded *except* when found in an attribute and the letter after the entity is an equals
sign or an ASCII alphanumeric; see https://html.spec.whatwg.org/#named-character-reference-state
I propose two new option flags for html_entity_decode:
ENT_HTML5_NOATTRIBUTE -- decodes all the semicolon-less entities in addition to the other HTML5
entities
ENT_HTML5_ATTRIBUTE -- decodes semicolon-less entities except when they are followed by an equals
sign or ASCII alphanumeric
This would allow authors to easily decode these legacy semicolon-less entities in the same way a
browser would.
Test script:
---------------
In PHP:
$ psysh
Psy Shell v0.9.9 (PHP 7.3.2-3 â cli) by Justin Hileman
>>> html_entity_decode('&foo', ENT_HTML5)
=> "&foo"
In a browser web console:
>document.body.innerHTML="&foo"
"&foo"
> document.body.innerHTML
"&foo"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77769&edit=1
Thread (5 messages)