From 8a797162f0d35edbc693784381b0091b76f513a0 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 14 Nov 2014 16:38:04 -0500 Subject: [PATCH] Consistently handle trailing slashes in subpage links. The link text for [[/Foo/]] is `Foo` and the link text for [[../Foo/]] is `Foo`. So far so good. But the link text for [[/Foo//]] is `Foo` while the link text for [[../Foo//]] is `Foo/`. We are stripping all trailing slashes in the first case, but not the second. Fix the code so that we strip all trailing slashes in both cases. Update some of the comments in the code while we are at it. Change-Id: Id61eacafea9820c404699a7902c8eb8102779516 --- includes/Linker.php | 9 ++++++--- tests/parser/parserTests.txt | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 0e9ef2b03a..168136ecc1 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1490,9 +1490,12 @@ class Linker { # Foobar -- normal # :Foobar -- override special treatment of prefix (images, language links) # /Foobar -- convert to CurrentPage/Foobar - # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text + # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial and final / from text # ../ -- convert to CurrentPage, from CurrentPage/CurrentSubPage - # ../Foobar -- convert to CurrentPage/Foobar, from CurrentPage/CurrentSubPage + # ../Foobar -- convert to CurrentPage/Foobar, + # (from CurrentPage/CurrentSubPage) + # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text + # (from CurrentPage/CurrentSubPage) wfProfileIn( __METHOD__ ); $ret = $target; # default return value is no change @@ -1538,7 +1541,7 @@ class Linker { $ret = implode( '/', array_slice( $exploded, 0, -$dotdotcount ) ); # / at the end means don't show full path if ( substr( $nodotdot, -1, 1 ) === '/' ) { - $nodotdot = substr( $nodotdot, 0, -1 ); + $nodotdot = rtrim( $nodotdot, '/' ); if ( $text === '' ) { $text = $nodotdot . $suffix; } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 8dfb4dd143..39129cba4c 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -16742,7 +16742,7 @@ subpage title=[[Subpage test/L1/L2/L3]] !! wikitext [[../../////]] !! html -

/// +

Subpage test/L1

!! end -- 2.20.1