diff options
Diffstat (limited to 'ext/standard/html.c')
-rw-r--r-- | ext/standard/html.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/ext/standard/html.c b/ext/standard/html.c index 075a4d2ff9..5bbe39ccbb 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -84,6 +84,18 @@ #define sjis_lead(c) ((c) != 0x80 && (c) != 0xA0 && (c) < 0xFD) #define sjis_trail(c) ((c) >= 0x40 && (c) != 0x7F && (c) < 0xFD) +/* {{{ get_default_charset + */ +static char *get_default_charset(TSRMLS_D) { + if (PG(internal_encoding) && PG(internal_encoding)[0]) { + return PG(internal_encoding); + } else if (SG(default_charset) && SG(default_charset)[0] ) { + return SG(default_charset); + } + return NULL; +} +/* }}} */ + /* {{{ get_next_char */ static inline unsigned int get_next_char( @@ -1432,8 +1444,8 @@ encode_amp: */ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) { - char *str, *hint_charset = PHP_DEFAULT_CHARSET; - int str_len, hint_charset_len = sizeof(PHP_DEFAULT_CHARSET)-1; + char *str, *hint_charset = NULL; + int str_len, hint_charset_len = 0; size_t new_len; long flags = ENT_COMPAT; char *replaced; @@ -1443,7 +1455,11 @@ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) return; } + if (!hint_charset) { + hint_charset = get_default_charset(TSRMLS_C); + } replaced = php_escape_html_entities_ex(str, str_len, &new_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC); + RETVAL_STRINGL(replaced, (int)new_len, 0); } /* }}} */ @@ -1504,8 +1520,8 @@ PHP_FUNCTION(htmlspecialchars_decode) Convert all HTML entities to their applicable characters */ PHP_FUNCTION(html_entity_decode) { - char *str, *hint_charset = PHP_DEFAULT_CHARSET; - int str_len, hint_charset_len = sizeof(PHP_DEFAULT_CHARSET)-1; + char *str, *hint_charset = NULL; + int str_len, hint_charset_len; size_t new_len = 0; long quote_style = ENT_COMPAT; char *replaced; @@ -1515,7 +1531,11 @@ PHP_FUNCTION(html_entity_decode) return; } + if (!hint_charset) { + hint_charset = get_default_charset(TSRMLS_C); + } replaced = php_unescape_html_entities(str, str_len, &new_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC); + if (replaced) { RETURN_STRINGL(replaced, (int)new_len, 0); } |