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
This commit is contained in:
Klaus Leithoff 2012-05-30 09:22:27 +00:00
parent 2427a60c90
commit b6638adc24
2 changed files with 17 additions and 2 deletions

View File

@ -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')
{

View File

@ -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';