@@ -498,8 +498,8 @@ public function xss_clean($str, $is_image = FALSE)
498
498
.'(?<attributes>(?:[\s\042\047/=]* ' // non-attribute characters, excluding > (tag close) for obvious reasons
499
499
.'[^\s\042\047>/=]+ ' // attribute characters
500
500
// optional attribute-value
501
- .'(?:\s*=\s* ' // attribute-value separator
502
- .'(?:\ 042[^\042]*\042|\047[^\047]*\047|[^\s\042\047=><`]*) ' // single, double or non-quoted value
501
+ .'(?:\s*= ' // attribute-value separator
502
+ .'(?:[^\s\ 042\047=><`]+|\s*\042 [^\042]*\042|\s*\ 047[^\047]*\047|\s*(?U: [^\s\042\047=><`]*) ) ' // single, double or non-quoted value
503
503
.')? ' // end optional attribute-value group
504
504
.')*) ' // end optional attributes group
505
505
.'[^>]*)(?<closeTag>\>)?#isS ' ;
@@ -808,7 +808,7 @@ protected function _sanitize_naughty_html($matches)
808
808
.'([\s\042\047/=]*) ' // non-attribute characters, excluding > (tag close) for obvious reasons
809
809
.'(?<name>[^\s\042\047>/=]+) ' // attribute characters
810
810
// optional attribute-value
811
- .'(?:\s*=(?: [^\s\042\047=><`]+|\s*\042[^\042]+ \042|\s*\047[^\047]+ \047|\s*(?U:[^\s\042\047=><`]*))) ' // attribute-value separator
811
+ .'(?:\s*=(?<value> [^\s\042\047=><`]+|\s*\042[^\042]* \042|\s*\047[^\047]* \047|\s*(?U:[^\s\042\047=><`]*))) ' // attribute-value separator
812
812
.'#i ' ;
813
813
814
814
if ($ count = preg_match_all ($ pattern , $ matches ['attributes ' ], $ attributes , PREG_SET_ORDER | PREG_OFFSET_CAPTURE ))
@@ -818,8 +818,14 @@ protected function _sanitize_naughty_html($matches)
818
818
// so we don't damage the string.
819
819
for ($ i = $ count - 1 ; $ i > -1 ; $ i --)
820
820
{
821
- // Is it indeed an "evil" attribute?
822
- if (preg_match ('#^( ' .implode ('| ' , $ evil_attributes ).')$#i ' , $ attributes [$ i ]['name ' ][0 ]))
821
+ if (
822
+ // Is it indeed an "evil" attribute?
823
+ preg_match ('#^( ' .implode ('| ' , $ evil_attributes ).')$#i ' , $ attributes [$ i ]['name ' ][0 ])
824
+ // Or an attribute not starting with a letter? Some parsers get confused by that
825
+ OR ! ctype_alpha ($ attributes [$ i ]['name ' ][0 ][0 ])
826
+ // Does it have an equals sign, but no value and not quoted? Strip that too!
827
+ OR (trim ($ attributes [$ i ]['value ' ][0 ]) === '' )
828
+ )
823
829
{
824
830
$ matches ['attributes ' ] = substr_replace (
825
831
$ matches ['attributes ' ],
0 commit comments