Skip to content

Commit c02f6fb

Browse files
committed
Output blocks of safe chars in php_filter_encode_html()
Fixes a long-standing TODO, and is faster.
1 parent 31b4f39 commit c02f6fb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ext/filter/sanitizing_filters.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ static void php_filter_encode_html(zval *value, const unsigned char *chars)
3131
size_t len = Z_STRLEN_P(value);
3232
unsigned char *s = (unsigned char *)Z_STRVAL_P(value);
3333
unsigned char *e = s + len;
34+
unsigned char *last_output = s;
3435

3536
if (Z_STRLEN_P(value) == 0) {
3637
return;
3738
}
3839

3940
while (s < e) {
4041
if (chars[*s]) {
42+
smart_str_appendl(&str, (const char *) last_output, s - last_output);
4143
smart_str_appendl(&str, "&#", 2);
4244
smart_str_append_unsigned(&str, (zend_ulong)*s);
4345
smart_str_appendc(&str, ';');
44-
} else {
45-
/* XXX: this needs to be optimized to work with blocks of 'safe' chars */
46-
smart_str_appendc(&str, *s);
46+
last_output = s + 1;
4747
}
4848
s++;
4949
}
5050

51+
smart_str_appendl(&str, (const char *) last_output, s - last_output);
52+
5153
zval_ptr_dtor(value);
5254
ZVAL_NEW_STR(value, smart_str_extract(&str));
5355
}

0 commit comments

Comments
 (0)