Skip to content

Commit

Permalink
Better regex for mungeRgb
Browse files Browse the repository at this point in the history
  • Loading branch information
f.godfrin committed Feb 9, 2017
1 parent 0bab4b9 commit 17a90a9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library/HTMLPurifier/AttrDef.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Besides defining (through code) what precisely makes the string valid,
* subclasses are also responsible for cleaning the code if possible.
*/

abstract class HTMLPurifier_AttrDef
{

Expand Down Expand Up @@ -85,13 +86,13 @@ public function make($string)
*/
protected function mungeRgb($string)
{
$p = '(\d+(\.\d+)?([%]?))';
$p = '\s*(\d+(\.\d+)?([%]?))\s*';

if (preg_match('/(rgba|hsla)\(/', $string)) {
return preg_replace('/(rgba|hsla)\(' . $p . '\s*,\s*' . $p . '\s*,\s*' . $p . '\s*,\s*' . $p . '\)/', '\1(\2,\5,\8,\11)', $string);
return preg_replace('/(rgba|hsla)\('.$p.','.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8,\11)', $string);
}

return preg_replace('/(rgb|hsl)\(' . $p . '\s*,\s*' . $p . '\s*,\s*' . $p . '\)/', '\1(\2,\5,\8)', $string);
return preg_replace('/(rgb|hsl)\('.$p.','.$p.','.$p.'\)/', '\1(\2,\5,\8)', $string);
}

/**
Expand Down

0 comments on commit 17a90a9

Please sign in to comment.