From b6638adc24209ec254bb134a345e2f145cf3109c Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Wed, 30 May 2012 09:22:27 +0000 Subject: [PATCH] handling of multibyte chars in attribute values of tags in mbstring.func_overload enviroments, as substr_replace does not have a multibyte func overload function associated. Thus substr_replace(, '', 0, strlen()) will fall short in the above mentioned enviroments; we use our own bytes-function now introduced into htmLawed --- phpgwapi/inc/class.egw_htmLawed.inc.php | 3 ++- phpgwapi/inc/htmLawed/htmLawed.php | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/phpgwapi/inc/class.egw_htmLawed.inc.php b/phpgwapi/inc/class.egw_htmLawed.inc.php index d5ebdfd94d..3de9ef078a 100644 --- a/phpgwapi/inc/class.egw_htmLawed.inc.php +++ b/phpgwapi/inc/class.egw_htmLawed.inc.php @@ -99,6 +99,7 @@ class egw_htmLawed */ function egw_htmLawed($html2check, $Config=null, $Spec=array()) { + //error_log(__METHOD__.__LINE__.' Input:'.$html2check); if (is_array($Config) && is_array($this->Configuration)) $Config = array_merge($this->Configuration, $Config); if (empty($Config)) $Config = $this->Configuration; if (empty($Spec)) $Spec = $this->Spec; @@ -116,7 +117,7 @@ class egw_htmLawed */ function hl_my_tag_transform($element, $attribute_array) { - //if ($element=='a') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array)); + //if ($element=='img') error_log(__METHOD__.__LINE__." ".$element.'->'.array2string($attribute_array)); // Elements other than 'img' or 'img' without a 'img' attribute are returned unchanged if($element == 'img') { diff --git a/phpgwapi/inc/htmLawed/htmLawed.php b/phpgwapi/inc/htmLawed/htmLawed.php index 4c926f2f7e..96fa2959a7 100644 --- a/phpgwapi/inc/htmLawed/htmLawed.php +++ b/phpgwapi/inc/htmLawed/htmLawed.php @@ -471,7 +471,7 @@ while(strlen($a)){ } break; case 2: // Val if(preg_match('`^"[^"]*"`', $a, $m) or preg_match("`^'[^']*'`", $a, $m) or preg_match("`^\s*[^\s\"']+`", $a, $m)){ - $m = $m[0]; $w = 1; $mode = 0; $a = ltrim(substr_replace($a, '', 0, strlen($m))); + $m = $m[0]; $w = 1; $mode = 0; $a = ltrim(substr_replace($a, '', 0, hl_bytes($m))); $aA[$nm] = trim(($m[0] == '"' or $m[0] == '\'') ? substr($m, 1, -1) : $m); } break; @@ -684,6 +684,20 @@ return str_replace(array("\x01", "\x02", "\x03", "\x04", "\x05", "\x07"), array( // eof } +/** + * Return the number of bytes of a string, independent of mbstring.func_overload + * AND the availability of mbstring + * + * @param string $str + * @return int + */ +function hl_bytes($str) +{ +static $func_overload; +if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0; +return $func_overload & 2 ? mb_strlen($str,'8bit') : strlen($str); +} + function hl_version(){ // rel return '1.1.10';