From c66c9aa5352743b2f87bc4627a1be529c5d18535 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Sun, 13 Aug 2017 14:19:13 -0400 Subject: [PATCH] Fix link prefix/suffixes around Category and Language links. Bug: T2087 Bug: T10897 Bug: T87753 Change-Id: I943cd9bec0855d9a326b0b50739d686a29995370 --- includes/parser/Parser.php | 16 +++++++++------- tests/parser/parserTests.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 326100280d..5ef0032f53 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2323,8 +2323,11 @@ class Parser { $this->mOutput->addLanguageLink( $nt->getFullText() ); } + /** + * Strip the whitespace interwiki links produce, see T10897 + */ $s = rtrim( $s . $prefix ); - $s .= trim( $trail, "\n" ) == '' ? '' : $prefix . $trail; + $s .= rtrim( $trail, "\n" ); continue; } @@ -2349,7 +2352,11 @@ class Parser { continue; } } elseif ( $ns == NS_CATEGORY ) { - $s = rtrim( $s . "\n" ); # T2087 + /** + * Strip the whitespace Category links produce, see T2087 + */ + $s = rtrim( $s . $prefix ); # T2087, T87753 + $s .= rtrim( $trail, "\n" ); if ( $wasblank ) { $sortkey = $this->getDefaultSort(); @@ -2361,11 +2368,6 @@ class Parser { $sortkey = $this->getConverterLanguage()->convertCategoryKey( $sortkey ); $this->mOutput->addCategory( $nt->getDBkey(), $sortkey ); - /** - * Strip the whitespace Category links produce, see T2087 - */ - $s .= trim( $prefix . $trail, "\n" ) == '' ? '' : $prefix . $trail; - continue; } } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index ab79b59409..2fa3cb05d0 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -15807,6 +15807,26 @@ parsoid=wt2html !! end +!! test +9. Categories and newlines: should behave properly with linkprefix (T87753) +!! options +language=ar +!! wikitext +foo bar +foo bar +[[تصنيف:Foo]] +[[تصنيف:Bar]] +!! html/php +

foo bar +foo bar +

+!! html/parsoid +

foo bar +foo bar

+ + +!! end + !! test Category links with multiple namespaces !! wikitext @@ -15854,6 +15874,20 @@ x[[Category:Foo]]y

xy

!! end +!! test +Link prefix/suffixes aren't applied to language links +!! options +parsoid=wt2html +language=is +!! wikitext +x[[es:Foo]]y +!! html/php +

xy +

+!! html/parsoid +

xy

+!! end + !! test Parsoid: Serialize link to file page with colon escape !! options -- 2.20.1