From: Aryeh Gregor Date: Fri, 11 Jun 2010 21:57:20 +0000 (+0000) Subject: Don't allow boolean HTML5 attribs into XHTML1 X-Git-Tag: 1.31.0-rc.0~36533 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=9fb4b59f35d9b0bdaab451e4ae454c7ce1da0de5 Don't allow boolean HTML5 attribs into XHTML1 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. --- diff --git a/includes/Html.php b/includes/Html.php index 9d017c7503..6fe6da83d6 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -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