From 6c544459fd980f8bbb23c7da63e52039d1af0b9f Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 22 Apr 2010 16:27:36 +0000 Subject: entity decoder; urlencoding of user in U() --- it_html.class | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'it_html.class') diff --git a/it_html.class b/it_html.class index fd2930e..675e852 100644 --- a/it_html.class +++ b/it_html.class @@ -422,6 +422,18 @@ function sanitize($html) return $GLOBALS['debug_q'] ? "$result" : $result; } +/** + * Decode all entities, ensure latin-1 encoding + */ +function entity_decode($string) +{ + $string = preg_replace('/&#(8217|65533);/', "'", html_entity_decode($string)); + $string = preg_replace('/�*([0-9a-f]+);/ei', 'hexdec("\\1") <= 255 ? chr(hexdec("\\1")) : " "', $string); + $string = preg_replace('/�*([0-9]+);/e', '\\1 <= 255 ? chr(\\1) : " "', $string); + + return $string; +} + /** * Replace or remove all illegal characters from a latin-1 string */ @@ -464,9 +476,9 @@ function U(/* ... */) $u['host'] = preg_match('/[^-_.0-9a-z]/i', $u['host']) && function_exists('idn_to_ascii') && ($idnahost = idn_to_ascii($GLOBALS['it_html']->p['charset'] == "iso-8859-1" ? utf8_encode($u['host']) : $u['host'])) ? $idnahost : $u['host']; # Punycode hostname to include into webpage $u['host'] = preg_replace('/[^-_.0-9a-z\x80-\xff]/ie', "rawurlencode('\$0')", $u['host']); # Encode garbage chars in host - # handle scheme, user, password, host + # handle scheme, user (urlencoded), password, host $hostpart = - ($u['user'] ? $u['user'] . ($u['pass'] ? ":" . $u['pass'] : "") . "@" : "") . + ($u['user'] ? preg_replace('|[^-\w.+!*(),:?@&=/~$%#]|e', 'urlencode(stripslashes("$0"))', $u['user'] . ($u['pass'] ? ":" . $u['pass'] : "") . "@") : "") . ($u['host'] ? $u['host'] : "") . ($u['port'] ? ":" . intval($u['port']) : ""); -- cgit v1.2.3