Don't allow boolean HTML5 attribs into XHTML1
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 11 Jun 2010 21:57:20 +0000 (21:57 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 11 Jun 2010 21:57:20 +0000 (21:57 +0000)
The code didn't handle the case where a non-associative array was passed
for the attributes, like array( 'autofocus' ) instead of array(
'autofocus' => '' ).  In retrospect, allowing this syntax was a bad
decision and I wish I hadn't.  Associative arrays shouldn't pretend to
be lists.  Probably too much trouble to change it now.

includes/Html.php

index 9d017c7..6fe6da8 100644 (file)
@@ -180,22 +180,6 @@ class Html {
                        if ( $element == 'textarea' && isset( $attribs['maxlength'] ) ) {
                                unset( $attribs['maxlength'] );
                        }
-                       # Here we're blacklisting some HTML5-only attributes...
-                       $html5attribs = array(
-                               'autocomplete',
-                               'autofocus',
-                               'max',
-                               'min',
-                               'multiple',
-                               'pattern',
-                               'placeholder',
-                               'required',
-                               'step',
-                               'spellcheck',
-                       );
-                       foreach ( $html5attribs as $badAttr ) {
-                               unset( $attribs[$badAttr] );
-                       }
                }
 
                return "<$element" . self::expandAttributes(
@@ -381,6 +365,22 @@ class Html {
                                continue;
                        }
 
+                       # Here we're blacklisting some HTML5-only attributes...
+                       if ( !$wgHtml5 && in_array( $key, array(
+                                       'autocomplete',
+                                       'autofocus',
+                                       'max',
+                                       'min',
+                                       'multiple',
+                                       'pattern',
+                                       'placeholder',
+                                       'required',
+                                       'step',
+                                       'spellcheck',
+                       ) ) ) {
+                               continue;
+                       }
+
                        # See the "Attributes" section in the HTML syntax part of HTML5,
                        # 9.1.2.3 as of 2009-08-10.  Most attributes can have quotation
                        # marks omitted, but not all.  (Although a literal " is not