Consistently handle trailing slashes in subpage links.
authorC. Scott Ananian <cscott@cscott.net>
Fri, 14 Nov 2014 21:38:04 +0000 (16:38 -0500)
committerC. Scott Ananian <cscott@cscott.net>
Fri, 14 Nov 2014 22:09:00 +0000 (17:09 -0500)
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
tests/parser/parserTests.txt

index 0e9ef2b..168136e 100644 (file)
@@ -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;
                                                        }
index 8dfb4dd..39129cb 100644 (file)
@@ -16742,7 +16742,7 @@ subpage title=[[Subpage test/L1/L2/L3]]
 !! wikitext
 [[../../////]]
 !! html
-<p><a href="/index.php?title=Subpage_test/L1////&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1//// (page does not exist)">///</a>
+<p><a href="/index.php?title=Subpage_test/L1&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1 (page does not exist)">Subpage test/L1</a>
 </p>
 !! end