diff --git a/NEWS b/NEWS index e39f51a6..e3a3ef73 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier browsers) but not others (which have spotty browser implementations) ! XHTML 1.1 mode now sort-of works without any fatal errors, and lang is now moved over to xml:lang. +! Attribute transformation smoketest available at smoketests/attrTransform.php - Possibly fatal bug with __autoload() fixed in module manager - Invert HTMLModuleManager->addModule() processing order to check prefixes first and then the literal module diff --git a/library/HTMLPurifier/HTMLModule/TransformToStrict.php b/library/HTMLPurifier/HTMLModule/TransformToStrict.php index a11f9f88..ce621b50 100644 --- a/library/HTMLPurifier/HTMLModule/TransformToStrict.php +++ b/library/HTMLPurifier/HTMLModule/TransformToStrict.php @@ -50,6 +50,13 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule function HTMLPurifier_HTMLModule_TransformToStrict() { + // behavior with transformations when there's another CSS property + // working on it is interesting: the CSS will *always* override + // the deprecated attribute, whereas an inline CSS declaration will + // override the corresponding declaration in, say, an external + // stylesheet. This behavior won't affect most people, but it + // does represent an operational difference we CANNOT fix. + // deprecated tag transforms $this->info_tag_transform['font'] = new HTMLPurifier_TagTransform_Font(); $this->info_tag_transform['menu'] = new HTMLPurifier_TagTransform_Simple('ul'); @@ -99,6 +106,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule $this->info['td']->attr_transform_pre['width'] = $this->info['th']->attr_transform_pre['width'] = $this->info['hr']->attr_transform_pre['width'] = new HTMLPurifier_AttrTransform_Length('width'); + $this->info['td']->attr_transform_pre['nowrap'] = $this->info['th']->attr_transform_pre['nowrap'] = new HTMLPurifier_AttrTransform_BoolToCSS('nowrap', 'white-space:nowrap;'); @@ -109,7 +117,10 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule $this->info['img']->attr_transform_pre['vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace'); $this->info['hr']->attr_transform_pre['size'] = new HTMLPurifier_AttrTransform_Length('size', 'height'); - $this->info['hr']->attr_transform_pre['noshade'] = new HTMLPurifier_AttrTransform_BoolToCSS('noshade', 'border-style:solid;'); + + // this transformation is not precise but often good enough. + // different browsers use different styles to designate noshade + $this->info['hr']->attr_transform_pre['noshade'] = new HTMLPurifier_AttrTransform_BoolToCSS('noshade', 'color:#808080;background-color:#808080;border: 0;'); $this->info['br']->attr_transform_pre['clear'] = new HTMLPurifier_AttrTransform_EnumToCSS('clear', array( @@ -119,12 +130,16 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule 'none' => 'clear:none;', )); + // this is a slightly unreasonable attribute $this->info['caption']->attr_transform_pre['align'] = new HTMLPurifier_AttrTransform_EnumToCSS('align', array( + // we're following IE's behavior, not Firefox's, due + // to the fact that no one supports caption-side:right, + // W3C included (with CSS 2.1) 'left' => 'text-align:left;', 'right' => 'text-align:right;', 'top' => 'caption-side:top;', - 'bottom' => 'caption-side:bottom;' + 'bottom' => 'caption-side:bottom;' // not supported by IE )); $this->info['table']->attr_transform_pre['align'] = diff --git a/smoketests/attrTransform.php b/smoketests/attrTransform.php new file mode 100644 index 00000000..7b6a4fd1 --- /dev/null +++ b/smoketests/attrTransform.php @@ -0,0 +1,68 @@ + + + + HTML Purifier Attribute Transformation Smoketest + + + + +

HTML Purifier Attribute Transformation Smoketest

+
+
+ HTML +
+
+ CSS +
+
+Requires PHP 5.

'); + +$xml = simplexml_load_file('attrTransform.xml'); + +// attr transform enabled HTML Purifier +$config = HTMLPurifier_Config::createDefault(); +$purifier = new HTMLPurifier($config); + +$title = isset($_GET['title']) ? $_GET['title'] : true; + +foreach ($xml->group as $group) { + echo '

' . $group['title'] . '

'; + foreach ($group->sample as $sample) { + $sample = (string) $sample; +?> +
+
+ +
+
+ purify($sample); ?> +
+
+ + + \ No newline at end of file diff --git a/smoketests/attrTransform.xml b/smoketests/attrTransform.xml new file mode 100644 index 00000000..966d11a4 --- /dev/null +++ b/smoketests/attrTransform.xml @@ -0,0 +1,173 @@ + + + +
  • menu
  • ]]>
    +
  • dir
  • ]]>
    +
    + + Red]]> + #0000FF]]> + Arial]]> + + + -99]]> + 0]]> + 1]]> + 2]]> + 3]]> + 4]]> + 5]]> + 6]]> + 7]]> + 8]]> + 99]]> + + + Centered]]> + + + Left

    ]]>
    + Center

    ]]>
    + Right

    ]]>
    +
    + + + + To + Be + + + Or + Not + + + To + Be + + + ]]> + + + Or + Not + + + To + Be + + + ]]> + + + ]]> + I]]> + + + + + x1 + x2 + + + ]]> + + + x1 + x2 + + + ]]> +
    ]]>
    +
    + + + + This wants to wrap + really badly yes it does + + + ]]> + + + This wants to wrap + really badly yes it does + + + ]]> + + + tall]]> + + + a]]> +
    o]]>
    +
    + + ]]> + ]]> + + + B
    A]]>
    + B
    A]]>
    + IB
    A]]>
    + IB
    A]]>
    +
    + + + Left + 1.11.2 + + ]]> + + Right + 1.11.2 + + ]]> + + Top + 1.11.2 + + ]]> + + Bottom + 1.11.2 + + ]]> + + + ]]> + ]]> + top]]> + bottom]]> + middle]]> + + + lefta]]> + centera]]> + righta]]> + + + left]]> + center]]> + right]]> + + + + +
    \ No newline at end of file diff --git a/smoketests/img.png b/smoketests/img.png new file mode 100644 index 00000000..a755bcb5 Binary files /dev/null and b/smoketests/img.png differ diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 04ce22fe..2d5baeec 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -326,7 +326,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends ); $this->assertResult( '
    ', - '
    ' + '
    ' ); // align transformation $this->assertResult(