From 5e72d3501e5abf7c47104268845f09f74003a711 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 23 Aug 2009 21:06:54 +0000 Subject: [PATCH] Emit CDATA more intelligently This fixes some possible XML invalidity from r54767: CDATA stuff was being added only if $wgHtml5 was false, instead of whenever $wgWellFormedXml is true. Also, it uses CDATA for script as well as style, but in both cases only uses it if there's a & or < somewhere. --- includes/HTMLForm.php | 1 - includes/Html.php | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 59429c9077..35fb020ffe 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -1,7 +1,6 @@ */"; } return self::rawElement( 'script', $attrs, $contents ); @@ -294,15 +296,15 @@ class Html { * @return string Raw HTML */ public static function inlineStyle( $contents, $media = null ) { - global $wgHtml5; + global $wgHtml5, $wgWellFormedXml; $attrs = array(); if ( !$wgHtml5 ) { - # Technically we should probably add CDATA stuff here like with - # scripts, but in practice, stylesheets tend not to have - # problematic characters anyway. $attrs['type'] = 'text/css'; } + if ( $wgWellFormedXml && preg_match( '/[<&]/', $contents ) ) { + $contents = "/**/"; + } if ( $media !== null ) { $attrs['media'] = $media; } -- 2.20.1