Skip to content

Commit cf4fd53

Browse files
committed
When decoding, use ENT_HTML5 by default
1 parent 81e23f9 commit cf4fd53

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ function headers_list(): array {}
514514

515515
function htmlspecialchars(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE, ?string $encoding = null, bool $double_encode = true): string {}
516516

517-
function htmlspecialchars_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE): string {}
517+
function htmlspecialchars_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5): string {}
518518

519-
function html_entity_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE, ?string $encoding = null): string {}
519+
function html_entity_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, ?string $encoding = null): string {}
520520

521521
function htmlentities(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE, ?string $encoding = null, bool $double_encode = true): string {}
522522

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,12 @@ ZEND_END_ARG_INFO()
772772

773773
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_htmlspecialchars_decode, 0, 1, IS_STRING, 0)
774774
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
775-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ENT_QUOTES | ENT_SUBSTITUTE")
775+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5")
776776
ZEND_END_ARG_INFO()
777777

778778
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_html_entity_decode, 0, 1, IS_STRING, 0)
779779
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
780-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ENT_QUOTES | ENT_SUBSTITUTE")
780+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5")
781781
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
782782
ZEND_END_ARG_INFO()
783783

ext/standard/html.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(const unsigned char *old, size_t
13161316
static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
13171317
{
13181318
zend_string *str, *hint_charset = NULL;
1319-
zend_long flags = ENT_QUOTES|ENT_SUBSTITUTE;
1319+
zend_long flags = ENT_QUOTES|ENT_SUBSTITUTE; /* HTML401, to avoid ' - for MS Outlook, and Android 4 */
13201320
zend_string *replaced;
13211321
zend_bool double_encode = 1;
13221322

@@ -1367,7 +1367,7 @@ PHP_FUNCTION(htmlspecialchars)
13671367
PHP_FUNCTION(htmlspecialchars_decode)
13681368
{
13691369
zend_string *str;
1370-
zend_long quote_style = ENT_QUOTES|ENT_SUBSTITUTE;
1370+
zend_long quote_style = ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML5; /* HTML5 to decode ' */
13711371
zend_string *replaced;
13721372

13731373
ZEND_PARSE_PARAMETERS_START(1, 2)
@@ -1385,7 +1385,7 @@ PHP_FUNCTION(htmlspecialchars_decode)
13851385
PHP_FUNCTION(html_entity_decode)
13861386
{
13871387
zend_string *str, *hint_charset = NULL;
1388-
zend_long quote_style = ENT_QUOTES|ENT_SUBSTITUTE;
1388+
zend_long quote_style = ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML5;
13891389
zend_string *replaced;
13901390

13911391
ZEND_PARSE_PARAMETERS_START(1, 3)

ext/standard/tests/strings/html_entity_decode2.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ html_entity_decode: Handling of '
33
--FILE--
44
<?php
55

6+
echo "*** Default (should decode) ***\n";
7+
echo html_entity_decode("&apos;"), "\n";
8+
69
echo "*** HTML 4.01 implicit (shouldn't decode) ***\n";
710
echo html_entity_decode("&apos;", ENT_QUOTES, "UTF-8"), "\n";
811

@@ -21,6 +24,8 @@ echo html_entity_decode("&apos;", ENT_QUOTES | ENT_XML1, "UTF-8"), "\n";
2124
echo "Done.\n";
2225
?>
2326
--EXPECT--
27+
*** Default (should decode) ***
28+
'
2429
*** HTML 4.01 implicit (shouldn't decode) ***
2530
&apos;
2631
*** HTML 4.01 (shouldn't decode) ***

ext/standard/tests/strings/html_entity_decode3.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ echo "\nDone.\n";
213213
&#x09; DECODED
214214
&#x0A; DECODED
215215
&#x0B; NOT DECODED
216-
&#x0C; NOT DECODED
217-
&#x0D; DECODED
216+
&#x0C; DECODED
217+
&#x0D; NOT DECODED
218218
&#x0E; NOT DECODED
219219
&#x1F; NOT DECODED
220220
&#x20; DECODED
@@ -227,13 +227,13 @@ echo "\nDone.\n";
227227
&#xD800; NOT DECODED
228228
&#xDFFF; NOT DECODED
229229
&#xE000; DECODED
230-
&#xFFFE; DECODED
231-
&#xFFFF; DECODED
230+
&#xFFFE; NOT DECODED
231+
&#xFFFF; NOT DECODED
232232
&#xFDCF; DECODED
233-
&#xFDD0; DECODED
234-
&#xFDEF; DECODED
233+
&#xFDD0; NOT DECODED
234+
&#xFDEF; NOT DECODED
235235
&#xFDF0; DECODED
236-
&#x2FFFE; DECODED
237-
&#x2FFFF; DECODED
236+
&#x2FFFE; NOT DECODED
237+
&#x2FFFF; NOT DECODED
238238

239239
Done.

0 commit comments

Comments
 (0)