r102671 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102670‎ | r102671 | r102672 >
Date:18:02, 10 November 2011
Author:gicode
Status:ok (Comments)
Tags:
Comment:
Follow-up r102587. Add details to comments and add a couple more tests.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php
@@ -23,11 +23,14 @@
2424 array( '/a/b/c/./../../g', '/a/g' ),
2525 array( 'mid/content=5/../6', 'mid/6' ),
2626 array( '/a//../b', '/a/b' ),
 27+ array( '/.../a', '/.../a' ),
 28+ array( '.../a', '.../a' ),
2729 array( '', '' ),
2830 array( '/', '/' ),
2931 array( '//', '//' ),
3032 array( '.', '' ),
3133 array( '..', '' ),
 34+ array( '...', '...' ),
3235 array( '/.', '/' ),
3336 array( '/..', '/' ),
3437 array( './', '' ),
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -503,22 +503,23 @@
504504 while ( $urlPath ) {
505505 $matches = null;
506506 if ( preg_match('%^\.\.?/%', $urlPath, $matches) ) {
507 - # Step A
 507+ # Step A, remove leading "../" or "./"
508508 $urlPath = substr( $urlPath, strlen( $matches[0] ) );
509509 } elseif ( preg_match( '%^/\.(/|$)%', $urlPath, $matches ) ) {
510 - # Step B
 510+ # Step B, replace leading "/.$" or "/./" with "/"
511511 $start = strlen( $matches[0] );
512512 $urlPath = '/' . substr( $urlPath, $start );
513513 } elseif ( preg_match( '%^/\.\.(/|$)%', $urlPath, $matches ) ) {
514 - # Step C
 514+ # Step C, replace leading "/..$" or "/../" with "/" and
 515+ # remove last path component in output
515516 $start = strlen( $matches[0] );
516517 $urlPath = '/' . substr( $urlPath, $start );
517518 $output = preg_replace('%(^|/)[^/]*$%', '', $output);
518519 } elseif ( preg_match( '%^\.\.?$%', $urlPath, $matches ) ) {
519 - # Step D
520 - $urlPath = substr( $urlPath, strlen( $matches[0] ) );
 520+ # Step D, remove "^..$" or "^.$"
 521+ $urlPath = '';
521522 } else {
522 - # Step E
 523+ # Step E, move leading path segment to output
523524 preg_match( '%^/?[^/]*%', $urlPath, $matches );
524525 $urlPath = substr( $urlPath, strlen( $matches[0] ) );
525526 $output .= $matches[0];

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102587Add wfRemoveDotSegments and unit tests. This is a sane step towards fixing...gicode22:44, 9 November 2011

Comments

#Comment by 😂 (talk | contribs)   21:29, 12 November 2011

You also seemed to change Step D, was that intentional?

#Comment by GICodeWarrior (talk | contribs)   21:39, 12 November 2011

Yes, they are functionally identical. Step D only happens if the string contains exactly one or two dots and its goal is to remove them. http://tools.ietf.org/html/rfc3986#section-5.2.4

I had the substr in there before because I was trying to abstract it out to the bottom and later decided against it.

Also, the tests still pass. :-)

#Comment by 😂 (talk | contribs)   21:40, 12 November 2011

Fair enough, was just asking :)

Status & tagging log