Skip to content

Commit 7aa43a8

Browse files
committed
- Revamp of the decoding portion of html.c.
- Dramatic improvements on the performance of html_entity_decode and htmlspecialchars_decode, as the string is now traversed only once. Speedups of 20 to 25 times with Windows release builds and a ~250 characters string (for 2nd and subsequent calls). - Consistent behavior on html_entity_decode. For instance, the entity in "&<" would be decoded, but not "&é". Not anymore. The code path for "basic" and non-basic entities is now mostly shared. - Code of html_entity_decode and htmlspecialchars_decode is now shared. - [DOC] More consistent behavior of htmlspecialchars_decode. Instead of translating only <, >, &, ", ' and ', now e.g. ", ', ', ', etc. are also decoded. - [DOC] Previous translation of unicode code points in numerical entities was seriously broken. When the code points for some character were not the same in unicode and the target encoding, the behavior could be an erroneous translation (e.g. 0x80-0xA0 in win-1252) or no translation at all. Added unicode translation tables for all single-byte encodings. Entities are not translated for multi-byte entities, except for ASCII characters whose code points are shared. We could add the huge translation tables (several thousand elements) for those encodings in the future. - Fixed numerical entities that after # had text accepted by strcol being accepted. - Much more commented and well-structured code... - Tests for get_html_translation_table()) are broken. I stared fixing the tests, but then I realized it was completely helpless because get_html_translation_table() is broken by not handling multi-byte characters correctly.
1 parent b1d5cf7 commit 7aa43a8

13 files changed

+5690
-665
lines changed

ext/standard/basic_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,7 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC) /*
34323432
BG(left) = -1;
34333433
BG(user_tick_functions) = NULL;
34343434
BG(user_filter_map) = NULL;
3435+
BG(inverse_ent_maps) = NULL;
34353436

34363437
memset(&BG(serialize), 0, sizeof(BG(serialize)));
34373438
memset(&BG(unserialize), 0, sizeof(BG(unserialize)));
@@ -3454,6 +3455,10 @@ static void basic_globals_dtor(php_basic_globals *basic_globals_p TSRMLS_DC) /*
34543455
zend_hash_destroy(BG(url_adapt_state_ex).tags);
34553456
free(BG(url_adapt_state_ex).tags);
34563457
}
3458+
if (BG(inverse_ent_maps)) {
3459+
zend_hash_destroy(BG(inverse_ent_maps));
3460+
pefree(BG(inverse_ent_maps), 1);
3461+
}
34573462
}
34583463
/* }}} */
34593464

ext/standard/basic_functions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ typedef struct _php_basic_globals {
220220

221221
HashTable *user_filter_map;
222222

223+
/* html.c */
224+
/* map entities to characters. Stores hash table pointers for each charset */
225+
HashTable *inverse_ent_maps;
226+
223227
/* file.c */
224228
#if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
225229
mbstate_t mblen_state;

0 commit comments

Comments
 (0)