0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 18:55:19 +00:00

[1.6.1] Transformation of font's size attribute now handles super-large numbers

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1020 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-05-05 18:56:45 +00:00
parent 92ea74cba2
commit bd6071cb3b
3 changed files with 20 additions and 3 deletions

1
NEWS
View File

@ -30,6 +30,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
! XHTML 1.1 mode now sort-of works without any fatal errors, and ! XHTML 1.1 mode now sort-of works without any fatal errors, and
lang is now moved over to xml:lang. lang is now moved over to xml:lang.
! Attribute transformation smoketest available at smoketests/attrTransform.php ! Attribute transformation smoketest available at smoketests/attrTransform.php
! Transformation of font's size attribute now handles super-large numbers
- Possibly fatal bug with __autoload() fixed in module manager - Possibly fatal bug with __autoload() fixed in module manager
- Invert HTMLModuleManager->addModule() processing order to check - Invert HTMLModuleManager->addModule() processing order to check
prefixes first and then the literal module prefixes first and then the literal module

View File

@ -20,6 +20,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
var $transform_to = 'span'; var $transform_to = 'span';
var $_size_lookup = array( var $_size_lookup = array(
'0' => 'xx-small',
'1' => 'xx-small', '1' => 'xx-small',
'2' => 'small', '2' => 'small',
'3' => 'medium', '3' => 'medium',
@ -28,9 +29,10 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
'6' => 'xx-large', '6' => 'xx-large',
'7' => '300%', '7' => '300%',
'-1' => 'smaller', '-1' => 'smaller',
'+1' => 'larger',
'-2' => '60%', '-2' => '60%',
'+1' => 'larger',
'+2' => '150%', '+2' => '150%',
'+3' => '200%',
'+4' => '300%' '+4' => '300%'
); );
@ -58,6 +60,15 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
// handle size transform // handle size transform
if (isset($attr['size'])) { if (isset($attr['size'])) {
// normalize large numbers
if ($attr['size']{0} == '+' || $attr['size']{0} == '-') {
$size = (int) $attr['size'];
if ($size < -2) $attr['size'] = '-2';
if ($size > 4) $attr['size'] = '+4';
} else {
$size = (int) $attr['size'];
if ($size > 7) $attr['size'] = '7';
}
if (isset($this->_size_lookup[$attr['size']])) { if (isset($this->_size_lookup[$attr['size']])) {
$prepend_style .= 'font-size:' . $prepend_style .= 'font-size:' .
$this->_size_lookup[$attr['size']] . ';'; $this->_size_lookup[$attr['size']] . ';';

View File

@ -10,7 +10,8 @@
<sample><![CDATA[<font face="Arial">Arial</font>]]></sample> <sample><![CDATA[<font face="Arial">Arial</font>]]></sample>
</group> </group>
<group title="font.size"> <group title="font.size">
<sample><![CDATA[<font size="-99">-99</font>]]></sample> <sample><![CDATA[<font size="-2">-2</font>]]></sample>
<sample><![CDATA[<font size="-1">-1</font>]]></sample>
<sample><![CDATA[<font size="0">0</font>]]></sample> <sample><![CDATA[<font size="0">0</font>]]></sample>
<sample><![CDATA[<font size="1">1</font>]]></sample> <sample><![CDATA[<font size="1">1</font>]]></sample>
<sample><![CDATA[<font size="2">2</font>]]></sample> <sample><![CDATA[<font size="2">2</font>]]></sample>
@ -20,7 +21,11 @@
<sample><![CDATA[<font size="6">6</font>]]></sample> <sample><![CDATA[<font size="6">6</font>]]></sample>
<sample><![CDATA[<font size="7">7</font>]]></sample> <sample><![CDATA[<font size="7">7</font>]]></sample>
<sample><![CDATA[<font size="8">8</font>]]></sample> <sample><![CDATA[<font size="8">8</font>]]></sample>
<sample><![CDATA[<font size="99">99</font>]]></sample> <sample><![CDATA[<font size="+1">+1</font>]]></sample>
<sample><![CDATA[<font size="+2">+2</font>]]></sample>
<sample><![CDATA[<font size="+3">+3</font>]]></sample>
<sample><![CDATA[<font size="+4">+4</font>]]></sample>
<sample><![CDATA[<font size="+5">+5</font>]]></sample>
</group> </group>
<group title="center"> <group title="center">
<sample><![CDATA[<center>Centered</center>]]></sample> <sample><![CDATA[<center>Centered</center>]]></sample>