CSSMin: remove dot segments in relative local URLs
authorOri Livneh <ori@wikimedia.org>
Sun, 16 Aug 2015 17:32:13 +0000 (10:32 -0700)
committerOri Livneh <ori@wikimedia.org>
Sun, 16 Aug 2015 17:41:45 +0000 (10:41 -0700)
Call wfRemoveDotSegments() (if available) on relative local URLs, so that
relative dot segments are collapsed.

Change-Id: Icc1c23a2a7d96c869412965bd8c3730d3c3b3a53

includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php

index f415c9b..118463a 100644 (file)
@@ -399,7 +399,7 @@ class CSSMin {
 
                if ( $local === false ) {
                        // Assume that all paths are relative to $remote, and make them absolute
-                       return $remote . '/' . $url;
+                       $url = $remote . '/' . $url;
                } else {
                        // We drop the query part here and instead make the path relative to $remote
                        $url = "{$remote}/{$file}";
@@ -418,8 +418,11 @@ class CSSMin {
                        }
                        // If any of these conditions failed (file missing, we don't want to embed it
                        // or it's not embeddable), return the URL (possibly with ?timestamp part)
-                       return $url;
                }
+               if ( function_exists( 'wfRemoveDotSegments' ) ) {
+                       $url = wfRemoveDotSegments( $url );
+               }
+               return $url;
        }
 
        /**
index 6142f96..dc3809f 100644 (file)
@@ -102,12 +102,12 @@ class CSSMinTest extends MediaWikiTestCase {
                        array(
                                'Without trailing slash',
                                array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ),
-                               'foo { prop: url(http://example.org/quux/../bar.png); }',
+                               'foo { prop: url(http://example.org/bar.png); }',
                        ),
                        array(
                                'With trailing slash on remote (bug 27052)',
                                array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ),
-                               'foo { prop: url(http://example.org/quux/../bar.png); }',
+                               'foo { prop: url(http://example.org/bar.png); }',
                        ),
                        array(
                                'Guard against stripping double slashes from query',