From 92ea74cba296250de7fe7a2697b1b81af38420df Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 5 May 2007 18:41:53 +0000 Subject: [PATCH] [1.6.1] Add attribute transformation smoketests - Repair broken noshade implementation - Add lots of advisory comments to TransformToStrict.php git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1019 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + .../HTMLModule/TransformToStrict.php | 19 +- smoketests/attrTransform.php | 68 +++++++ smoketests/attrTransform.xml | 173 ++++++++++++++++++ smoketests/img.png | Bin 0 -> 2138 bytes .../Strategy/ValidateAttributesTest.php | 2 +- 6 files changed, 260 insertions(+), 3 deletions(-) create mode 100644 smoketests/attrTransform.php create mode 100644 smoketests/attrTransform.xml create mode 100644 smoketests/img.png 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 0000000000000000000000000000000000000000..a755bcb5edbb34f9795364dd147f6d3c58465c86 GIT binary patch literal 2138 zcmV-g2&MOlP)U-u*QjPY~x+q*!!Bf{V}^P zE~UxZ9-G1*X|$T1-I;T~x%b?2&OM^4s*1Z=BzL)F0Av7U0Av7U0Av7U0Av8%wPMWR zv*rQIfh9l{Pz>ZIuZ;j#flI(ypatl?69D7`4+4(@D}Vx@&qrZlAr%!B6c!c&(BI!r zFc_r2zn^F{3NQ$q0DcJ^0m5D>C_GAr0>IaSr+~_`vNG1MU(c#lt0*lk#j-3wAcXs4 ztpPN#Sd6Z&E}EO0IdI?rSFT(ExC}f8><5Pb9{_wF*b6MGudip@w(V3es7A?uyBqCV ze6unsB7p5UT)cRZ9ox6l+}sRs0r)QP+U*L!2kZjAQ(0NbPxd`e?S1zlrNGhpmPX%F zF(Ht`{cl^_IiB431f89o06zvc1JUVFS``!&Ovil+fP+B8SJ$oMr!T(9$4W|Yw1e%q z#%oQQhsJR^7aqdV8r!j_ zbzUi{kV0_i$PvEx)VI)5z6GoWLbD0L2mBWJ-2RtdV%5r(#1nSf!#$m8VHyS}{`wcz zH8hYM1z(!VbeQTC_yO>>?YnmIz-J#I5{qLy4vyB|9F9Z6wy7*Hr)2(o{`B_SH9!{d z=4=3X2-x?fkH*{eGhH_>6|IKGP%;iSWo*zRU+*U1xxmlZg{18wsulmTr1_Gk(9H!Qo+MT1F!g z3IYK(J-wN4Kl#Mcq)yMx1b}>CRB{2;Hr4)uV+;b@qQlOCtAyBDgD2)*`GCIa5>gssoP~)7W zj<0(KV2L9HBV(hybLt-$rio#in3muD%<^MdK1|bOEUJ(~x)7uS2Q14qUMYo<{FKT- z36=a_Vi@i@fKn29Lxy;308#P_i&4tNw&P2@1W+NA!phDXH$)2e4N55x$qJj4@+RXA zr4Toy#E#Yot&!Ts2AqT@o&Xt(yZ1w)42i%Ee}$L`!?|H(*up_bMRp*U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urifier/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(