Enforce attribute order?
April 08, 2008 08:19PM

I'm using HTMLpurifier in combination with FCKeditor, and PEAR's Text_Diff to power a proprietary, HTML-based wiki solution.

Unfortunately, FCK has a nasty habit of reversing attribute order on tags. So

<a href="x" title="j">


<a title="j" href="x">

after editing in FCK; editing again gets you back to

<a href="x" title="j">


This results in text_diff seeing a change on every tag with more than 1 attribute, on every wiki edit, meaning wiki diffs are unreadable.

My question is this: how hard would it be to have HTML purifier enforce an arbitrary attribute order? (e.g., alphabetical, so that 'href' always comes before 'title')

Re: Enforce attribute order?
April 08, 2008 08:54PM

That's... weird. O.o

Try this patch:

Index: HTMLPurifier/Generator.php
--- HTMLPurifier/Generator.php	(revision 1646)
+++ HTMLPurifier/Generator.php	(working copy)
@@ -141,6 +141,7 @@
     public function generateAttributes($assoc_array_of_attributes, $element) {
         $html = &#039;&#039;;
+        ksort($assoc_array_of_attributes);
         foreach ($assoc_array_of_attributes as $key => $value) {
             if (!$this->_xhtml) {
                 // remove namespaced attributes

I'll add proper support for it in 3.1.0.

Re: Enforce attribute order?
June 23, 2008 08:48PM

Finally got a chance to test this today, and it works great.

Any chance you'll slip a formal version of this feature into a future release?


Re: Enforce attribute order?
June 23, 2008 10:01PM

Yeah, I should've, but I forgot to. Will do so in 3.1.2.

Re: Enforce attribute order?
June 24, 2008 10:37PM

Committed as 24f6db6. You'll need to use the %Output.SortAttr directive.

Sorry, you do not have permission to post/reply in this forum.