Follow-up r102587. Add details to comments and add a couple more tests.
authorgicode <gicode@localhost>
Thu, 10 Nov 2011 18:02:38 +0000 (18:02 +0000)
committergicode <gicode@localhost>
Thu, 10 Nov 2011 18:02:38 +0000 (18:02 +0000)
includes/GlobalFunctions.php
tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php

index 339cd09..0913fa2 100644 (file)
@@ -503,22 +503,23 @@ function wfRemoveDotSegments( $urlPath ) {
        while ( $urlPath ) {
                $matches = null;
                if ( preg_match('%^\.\.?/%', $urlPath, $matches) ) {
-                       # Step A
+                       # Step A, remove leading "../" or "./"
                        $urlPath = substr( $urlPath, strlen( $matches[0] ) );
                } elseif ( preg_match( '%^/\.(/|$)%', $urlPath, $matches ) ) {
-                       # Step B
+                       # Step B, replace leading "/.$" or "/./" with "/"
                        $start = strlen( $matches[0] );
                        $urlPath = '/' . substr( $urlPath, $start );
                } elseif ( preg_match( '%^/\.\.(/|$)%', $urlPath, $matches ) ) {
-                       # Step C
+                       # Step C, replace leading "/..$" or "/../" with "/" and
+                       # remove last path component in output
                        $start = strlen( $matches[0] );
                        $urlPath = '/' . substr( $urlPath, $start );
                        $output = preg_replace('%(^|/)[^/]*$%', '', $output);
                } elseif ( preg_match( '%^\.\.?$%', $urlPath, $matches ) ) {
-                       # Step D
-                       $urlPath = substr( $urlPath, strlen( $matches[0] ) );
+                       # Step D, remove "^..$" or "^.$"
+                       $urlPath = '';
                } else {
-                       # Step E
+                       # Step E, move leading path segment to output
                        preg_match( '%^/?[^/]*%', $urlPath, $matches );
                        $urlPath = substr( $urlPath, strlen( $matches[0] ) );
                        $output .= $matches[0];
index c606005..1cf0e0f 100644 (file)
@@ -23,11 +23,14 @@ class wfRemoveDotSegments extends MediaWikiTestCase {
                        array( '/a/b/c/./../../g', '/a/g' ),
                        array( 'mid/content=5/../6', 'mid/6' ),
                        array( '/a//../b', '/a/b' ),
+                       array( '/.../a', '/.../a' ),
+                       array( '.../a', '.../a' ),
                        array( '', '' ),
                        array( '/', '/' ),
                        array( '//', '//' ),
                        array( '.', '' ),
                        array( '..', '' ),
+                       array( '...', '...' ),
                        array( '/.', '/' ),
                        array( '/..', '/' ),
                        array( './', '' ),