Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php |
— | — | @@ -23,11 +23,14 @@ |
24 | 24 | array( '/a/b/c/./../../g', '/a/g' ), |
25 | 25 | array( 'mid/content=5/../6', 'mid/6' ), |
26 | 26 | array( '/a//../b', '/a/b' ), |
| 27 | + array( '/.../a', '/.../a' ), |
| 28 | + array( '.../a', '.../a' ), |
27 | 29 | array( '', '' ), |
28 | 30 | array( '/', '/' ), |
29 | 31 | array( '//', '//' ), |
30 | 32 | array( '.', '' ), |
31 | 33 | array( '..', '' ), |
| 34 | + array( '...', '...' ), |
32 | 35 | array( '/.', '/' ), |
33 | 36 | array( '/..', '/' ), |
34 | 37 | array( './', '' ), |
Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -503,22 +503,23 @@ |
504 | 504 | while ( $urlPath ) { |
505 | 505 | $matches = null; |
506 | 506 | if ( preg_match('%^\.\.?/%', $urlPath, $matches) ) { |
507 | | - # Step A |
| 507 | + # Step A, remove leading "../" or "./" |
508 | 508 | $urlPath = substr( $urlPath, strlen( $matches[0] ) ); |
509 | 509 | } elseif ( preg_match( '%^/\.(/|$)%', $urlPath, $matches ) ) { |
510 | | - # Step B |
| 510 | + # Step B, replace leading "/.$" or "/./" with "/" |
511 | 511 | $start = strlen( $matches[0] ); |
512 | 512 | $urlPath = '/' . substr( $urlPath, $start ); |
513 | 513 | } elseif ( preg_match( '%^/\.\.(/|$)%', $urlPath, $matches ) ) { |
514 | | - # Step C |
| 514 | + # Step C, replace leading "/..$" or "/../" with "/" and |
| 515 | + # remove last path component in output |
515 | 516 | $start = strlen( $matches[0] ); |
516 | 517 | $urlPath = '/' . substr( $urlPath, $start ); |
517 | 518 | $output = preg_replace('%(^|/)[^/]*$%', '', $output); |
518 | 519 | } elseif ( preg_match( '%^\.\.?$%', $urlPath, $matches ) ) { |
519 | | - # Step D |
520 | | - $urlPath = substr( $urlPath, strlen( $matches[0] ) ); |
| 520 | + # Step D, remove "^..$" or "^.$" |
| 521 | + $urlPath = ''; |
521 | 522 | } else { |
522 | | - # Step E |
| 523 | + # Step E, move leading path segment to output |
523 | 524 | preg_match( '%^/?[^/]*%', $urlPath, $matches ); |
524 | 525 | $urlPath = substr( $urlPath, strlen( $matches[0] ) ); |
525 | 526 | $output .= $matches[0]; |