diff options
author | Urban Müller | 2010-04-22 16:27:36 +0000 |
---|---|---|
committer | Urban Müller | 2010-04-22 16:27:36 +0000 |
commit | 6c544459fd980f8bbb23c7da63e52039d1af0b9f (patch) | |
tree | 1eb67ce958a46dff0c3d7d4e4b82e443a4fd70a5 /it_html.class | |
parent | 66baddc401b100a5eb93d337135b798e957b848b (diff) | |
download | itools-6c544459fd980f8bbb23c7da63e52039d1af0b9f.tar.gz itools-6c544459fd980f8bbb23c7da63e52039d1af0b9f.tar.bz2 itools-6c544459fd980f8bbb23c7da63e52039d1af0b9f.zip |
entity decoder; urlencoding of user in U()
Diffstat (limited to 'it_html.class')
-rw-r--r-- | it_html.class | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/it_html.class b/it_html.class index fd2930e..675e852 100644 --- a/it_html.class +++ b/it_html.class @@ -423,6 +423,18 @@ function sanitize($html) } /** + * 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 */ function latinize($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']) : ""); |