From: Platonides Date: Sat, 21 Jan 2012 16:27:27 +0000 (+0000) Subject: Bug 33845: Headings become cursive in TOC when they contain an image X-Git-Tag: 1.31.0-rc.0~25150 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=49e6e233ecb3c96ba890f8afaf324579156a9de4;p=lhc%2Fweb%2Fwiklou.git Bug 33845: Headings become cursive in TOC when they contain an image Fixes the problems with r102179 and r102179, as there are valid tags which begin the same, which meant they were not removed from the TOC (the second regex, intended to remove tag parameters, then converted into / ). The same problem existed in the original regex, but as there are no valid tags which begin with sup or sub, it never happened). Added comment explaining the tocline regex, and added a bunch of parser tests. --- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 51751aac1d..761149dd6a 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4048,9 +4048,11 @@ class Parser { # link text with suffix $safeHeadline = $this->replaceLinkHoldersText( $safeHeadline ); - # Strip out HTML (other than plain and : bug 8393, or : bug 26375) + # Strip out HTML (first regex removes any tag not allowed) + # Allowed tags are and (bug 8393), (bug 26375) and (r105284) + # We strip any parameter from accepted tags (second regex) $tocline = preg_replace( - array( '#<(?!/?(sup|sub|i|b)).*?'.'>#', '#<(/?(sup|sub|i|b)).*?'.'>#' ), + array( '#<(?!/?(sup|sub|i|b)(?: [^>]*)?>).*?'.'>#', '#<(/?(sup|sub|i|b))(?: .*?)?'.'>#' ), array( '', '<$1>' ), $safeHeadline ); diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 9c276e020b..6f5702d2e7 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -8976,6 +8976,99 @@ __TOC__ !! end +!! test +Bug 33845: Headings become cursive in TOC when they contain an image +!! options +title=[[Main Page]] +!! input +__TOC__ +== Image [[Image:foobar.jpg]] == +!! result +

Contents

+ +
+

[edit] Image Foobar.jpg

+ +!! end + +!! test +Bug 33845 (2): Headings become bold in TOC when they contain a blockquote +!! options +title=[[Main Page]] +!! input +__TOC__ +==
Quote
== +!! result +

Contents

+ +
+

[edit]
Quote

+ +!! end + +!! test +Unclosed tags in TOC +!! options +title=[[Main Page]] +!! input +__TOC__ +== Proof: 2 < 3 == +Hanc marginis exiguitas non caperet. +QED +!! result +

Contents

+ +
+

[edit] Proof: 2 < 3

+

Hanc marginis exiguitas non caperet. +QED +

+!! end + +!! test +Multiple tags in TOC +!! input +__TOC__ +== Foo Bar == + +== Foo
Bar
== +!! result +

Contents

+ +
+

[edit] Foo Bar

+

[edit] Foo
Bar

+ +!! end + +!! test +Tags with parameters in TOC +!! input +__TOC__ +== Hello == + +== Evilbye == +!! result +

Contents

+ +
+

[edit] Hello

+

[edit] b">Evilbye

+ +!! end + !! article MediaWiki:Bug32057 !! text