summaryrefslogtreecommitdiff
path: root/ext/standard/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/html.c')
-rw-r--r--ext/standard/html.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/ext/standard/html.c b/ext/standard/html.c
index 360639ea76..a7c58d5bce 100644
--- a/ext/standard/html.c
+++ b/ext/standard/html.c
@@ -790,7 +790,7 @@ static inline int numeric_entity_is_allowed(unsigned uni_cp, int document_type)
*/
static inline int process_numeric_entity(const char **buf, unsigned *code_point)
{
- long code_l;
+ zend_long code_l;
int hexadecimal = (**buf == 'x' || **buf == 'X'); /* TODO: XML apparently disallows "X" */
char *endptr;
@@ -804,7 +804,7 @@ static inline int process_numeric_entity(const char **buf, unsigned *code_point)
return FAILURE;
}
- code_l = strtol(*buf, &endptr, hexadecimal ? 16 : 10);
+ code_l = ZEND_STRTOL(*buf, &endptr, hexadecimal ? 16 : 10);
/* we're guaranteed there were valid digits, so *endptr > buf */
*buf = endptr;
@@ -813,7 +813,7 @@ static inline int process_numeric_entity(const char **buf, unsigned *code_point)
/* many more are invalid, but that depends on whether it's HTML
* (and which version) or XML. */
- if (code_l > 0x10FFFFL)
+ if (code_l > Z_L(0x10FFFF))
return FAILURE;
if (code_point != NULL)
@@ -856,7 +856,7 @@ static inline int process_named_entity_html(const char **buf, const char **start
static inline int resolve_named_entity_html(const char *start, size_t length, const entity_ht *ht, unsigned *uni_cp1, unsigned *uni_cp2)
{
const entity_cp_map *s;
- ulong hash = zend_inline_hash_func(start, length);
+ zend_ulong hash = zend_inline_hash_func(start, length);
s = ht->buckets[hash % ht->num_elems];
while (s->entity) {
@@ -1112,11 +1112,11 @@ PHPAPI zend_string *php_unescape_html_entities(unsigned char *old, size_t oldlen
if (oldlen > new_size) {
/* overflow, refuse to do anything */
- ret = STR_INIT((char*)old, oldlen, 0);
+ ret = zend_string_init((char*)old, oldlen, 0);
retlen = oldlen;
goto empty_source;
}
- ret = STR_ALLOC(new_size, 0);
+ ret = zend_string_alloc(new_size, 0);
ret->val[0] = '\0';
ret->len = oldlen;
retlen = oldlen;
@@ -1275,7 +1275,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle
}
}
- replaced = STR_ALLOC(maxlen, 0);
+ replaced = zend_string_alloc(maxlen, 0);
len = 0;
cursor = 0;
while (cursor < oldlen) {
@@ -1288,7 +1288,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle
/* guarantee we have at least 40 bytes to write.
* In HTML5, entities may take up to 33 bytes */
if (len > maxlen - 40) { /* maxlen can never be smaller than 128 */
- replaced = STR_SAFE_REALLOC(replaced, maxlen, 1, 128, 0);
+ replaced = zend_string_safe_realloc(replaced, maxlen, 1, 128, 0);
maxlen += 128;
}
@@ -1301,7 +1301,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle
len += replacement_len;
continue;
} else {
- STR_FREE(replaced);
+ zend_string_free(replaced);
return STR_EMPTY_ALLOC();
}
} else { /* SUCCESS */
@@ -1420,7 +1420,7 @@ encode_amp:
/* at this point maxlen - len >= 40 */
if (maxlen - len < ent_len + 2 /* & and ; */) {
/* ent_len < oldlen, which is certainly <= SIZE_MAX/2 */
- replaced = STR_SAFE_REALLOC(replaced, maxlen, 1, ent_len + 128, 0);
+ replaced = zend_string_safe_realloc(replaced, maxlen, 1, ent_len + 128, 0);
maxlen += ent_len + 128;
}
replaced->val[len++] = '&';
@@ -1442,30 +1442,30 @@ encode_amp:
*/
static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
{
- char *str, *hint_charset = NULL;
- int str_len, hint_charset_len = 0;
- long flags = ENT_COMPAT;
+ zend_string *str, *hint_charset = NULL;
+ char *default_charset;
+ zend_long flags = ENT_COMPAT;
zend_string *replaced;
zend_bool double_encode = 1;
#ifndef FAST_ZPP
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!b", &str, &str_len, &flags, &hint_charset, &hint_charset_len, &double_encode) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|lS!b", &str, &flags, &hint_charset, &double_encode) == FAILURE) {
return;
}
#else
ZEND_PARSE_PARAMETERS_START(1, 4)
- Z_PARAM_STRING(str, str_len)
+ Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(flags)
- Z_PARAM_STRING_EX(hint_charset, hint_charset_len, 1, 0)
+ Z_PARAM_STR_EX(hint_charset, 1, 0)
Z_PARAM_BOOL(double_encode);
ZEND_PARSE_PARAMETERS_END();
#endif
if (!hint_charset) {
- hint_charset = get_default_charset(TSRMLS_C);
+ default_charset = get_default_charset(TSRMLS_C);
}
- replaced = php_escape_html_entities_ex((unsigned char*)str, str_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC);
+ replaced = php_escape_html_entities_ex((unsigned char*)str->val, str->len, all, (int) flags, (hint_charset ? hint_charset->val : default_charset), double_encode TSRMLS_CC);
RETVAL_STR(replaced);
}
/* }}} */
@@ -1505,8 +1505,8 @@ PHP_FUNCTION(htmlspecialchars)
PHP_FUNCTION(htmlspecialchars_decode)
{
char *str;
- int str_len;
- long quote_style = ENT_COMPAT;
+ size_t str_len;
+ zend_long quote_style = ENT_COMPAT;
zend_string *replaced;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &quote_style) == FAILURE) {
@@ -1525,30 +1525,29 @@ PHP_FUNCTION(htmlspecialchars_decode)
Convert all HTML entities to their applicable characters */
PHP_FUNCTION(html_entity_decode)
{
- char *str, *hint_charset = NULL;
- int str_len, hint_charset_len = 0;
- size_t new_len = 0;
- long quote_style = ENT_COMPAT;
+ zend_string *str, *hint_charset = NULL;
+ char *default_charset;
+ zend_long quote_style = ENT_COMPAT;
zend_string *replaced;
#ifndef FAST_ZPP
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len,
- &quote_style, &hint_charset, &hint_charset_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|lS", &str,
+ &quote_style, &hint_charset) == FAILURE) {
return;
}
#else
ZEND_PARSE_PARAMETERS_START(1, 3)
- Z_PARAM_STRING(str, str_len)
+ Z_PARAM_STR(str)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(quote_style)
- Z_PARAM_STRING(hint_charset, hint_charset_len)
+ Z_PARAM_STR(hint_charset)
ZEND_PARSE_PARAMETERS_END();
#endif
if (!hint_charset) {
- hint_charset = get_default_charset(TSRMLS_C);
+ default_charset = get_default_charset(TSRMLS_C);
}
- replaced = php_unescape_html_entities((unsigned char*)str, str_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC);
+ replaced = php_unescape_html_entities((unsigned char*)str->val, str->len, 1 /*all*/, quote_style, (hint_charset ? hint_charset->val : default_charset) TSRMLS_CC);
if (replaced) {
RETURN_STR(replaced);
@@ -1626,13 +1625,13 @@ static inline void write_s3row_data(
Returns the internal translation table used by htmlspecialchars and htmlentities */
PHP_FUNCTION(get_html_translation_table)
{
- long all = HTML_SPECIALCHARS,
+ zend_long all = HTML_SPECIALCHARS,
flags = ENT_COMPAT;
int doctype;
entity_table_opt entity_table;
const enc_to_uni *to_uni_table = NULL;
char *charset_hint = NULL;
- int charset_hint_len;
+ size_t charset_hint_len;
enum entity_charset charset;
/* in this function we have to jump through some loops because we're