* (bug 11158) Fix escaping in API HTML-formatted JSON
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 10 Sep 2007 21:01:40 +0000 (21:01 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 10 Sep 2007 21:01:40 +0000 (21:01 +0000)
RELEASE-NOTES
includes/api/ApiFormatBase.php

index 0483623..9f76ecd 100644 (file)
@@ -44,6 +44,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   editinterface to a new permission key editusercssjs.
 * (bug 11266) Set fallback language for Fulfulde (ff) to French
 * (bug 11179) Include image version deletion comment in public log
+* (bug 11158) Fix escaping in API HTML-formatted JSON
 
 
 === API changes in 1.12 ===
index 209abd2..b69ebaf 100644 (file)
@@ -158,8 +158,11 @@ See <a href='http://www.mediawiki.org/wiki/API'>complete documentation</a>, or
        * This method also replaces any '<' with &lt;
        */
        protected function formatHTML($text) {
-               // encode all tags as safe blue strings
-               $text = ereg_replace('\<([^>]+)\>', '<span style="color:blue;">&lt;\1&gt;</span>', $text);
+               // Escape everything first for full coverage
+               $text = htmlspecialchars($text);
+               
+               // encode all comments or tags as safe blue strings
+               $text = preg_replace('/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text);
                // identify URLs
                $protos = "http|https|ftp|gopher";
                $text = ereg_replace("($protos)://[^ \\'\"()<\n]+", '<a href="\\0">\\0</a>', $text);