mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-08 06:48:42 +00:00
Fix mungeRgb to handle percent, float and hsl values
This commit is contained in:
parent
bd92f3531b
commit
0bab4b9fd0
@ -9,7 +9,6 @@
|
|||||||
* Besides defining (through code) what precisely makes the string valid,
|
* Besides defining (through code) what precisely makes the string valid,
|
||||||
* subclasses are also responsible for cleaning the code if possible.
|
* subclasses are also responsible for cleaning the code if possible.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class HTMLPurifier_AttrDef
|
abstract class HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -86,7 +85,13 @@ abstract class HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
protected function mungeRgb($string)
|
protected function mungeRgb($string)
|
||||||
{
|
{
|
||||||
return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string);
|
$p = '(\d+(\.\d+)?([%]?))';
|
||||||
|
|
||||||
|
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('/(rgb|hsl)\(' . $p . '\s*,\s*' . $p . '\s*,\s*' . $p . '\)/', '\1(\2,\5,\8)', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,12 +12,18 @@ class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarnes
|
|||||||
$this->assertDef($valid);
|
$this->assertDef($valid);
|
||||||
$this->assertDef('url(\'chess.png\') #333 50% top repeat fixed', $valid);
|
$this->assertDef('url(\'chess.png\') #333 50% top repeat fixed', $valid);
|
||||||
$this->assertDef(
|
$this->assertDef(
|
||||||
'rgb(34, 56, 33) url(chess.png) repeat fixed top',
|
'rgb(34%, 56%, 33%) url(chess.png) repeat fixed top',
|
||||||
'rgb(34,56,33) url("chess.png") repeat fixed top'
|
'rgb(34%,56%,33%) url("chess.png") repeat fixed top'
|
||||||
|
);
|
||||||
|
$this->assertDef(
|
||||||
|
'rgba(74, 12, 85, 0.35) repeat fixed bottom',
|
||||||
|
'rgba(74,12,85,.35) repeat fixed bottom'
|
||||||
|
);
|
||||||
|
$this->assertDef(
|
||||||
|
'hsl(244, 47.4%, 88.1%) right center',
|
||||||
|
'hsl(244,47.4%,88.1%) right center'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
// vim: et sw=4 sts=4
|
||||||
|
Loading…
Reference in New Issue
Block a user