Req #77769 [Opn]: html_entity_decode does not decode all HTML5 entities

From: Date: Tue, 19 Mar 2019 21:05:35 +0000
Subject: Req #77769 [Opn]: html_entity_decode does not decode all HTML5 entities
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220080@lists.php.net to get a copy of this message
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. &ampfoo 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('&ampfoo', ENT_HTML5)
=> "&ampfoo"

In a browser web console:
>document.body.innerHTML="&ampfoo"
"&ampfoo"
> document.body.innerHTML
"&foo"



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77769&edit=1


Thread (5 messages)

« previous php.bugs (#220080) next »