"Hashar" posted a comment on MediaWiki.r102587.
URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/102587#c27337

Commit summary for MediaWiki.r102587:

Add wfRemoveDotSegments and unit tests.  This is a sane step towards fixing
bug 32168.  This implements RFC3986 Section 5.2.4.
http://tools.ietf.org/html/rfc3986#section-5.2.4

This is important because you need to remove dot segments in order to safely
compare URLs when limiting URLs to a particular path.

Hashar's comment:

 if( preg_match('%^\.\.?/%', $urlPath, $matches) ) {
                        # Step A
                        $urlPath = substr( $urlPath, strlen( $matches[0] ) );
 }

Will match './' which is matched in Step B as well. You could just use substr() 
==  to compare. Would save you a preg_match call and a strlen call (since '../' 
is known to be 3 chars).

 } elseif ( preg_match( '%^/\.(/|$)%', $urlPath, $matches ) ) {
                        # Step B
                        $start = strlen( $matches[0] );
                        $urlPath = '/' . substr( $urlPath, $start );

Same there, isn't strlen( $matches[0] ) always 3 here? Plus setting $start and 
using it only once after is not that helpful. 


I am wondering if there is an existent PEAR implementation for this algorithm. 
Will avoid us reinventing the wheel and creating new bugs. We could ship the 
upstream lib in ./includes/libs and still run test on it.

_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview

Reply via email to