mirror of
https://github.com/mrclay/minify.git
synced 2025-08-28 16:19:59 +02:00
CSS/UriRewriter.php : fix Issue 99
ImportProcessor.php : fix Issue 99
This commit is contained in:
@@ -236,12 +236,14 @@ class Minify_CSS_UriRewriter {
|
||||
self::$debugText .= "docroot stripped : {$path}\n";
|
||||
|
||||
// fix to root-relative URI
|
||||
$uri = strtr($path, DIRECTORY_SEPARATOR, '/');
|
||||
|
||||
$uri = strtr($path, '/\\', '//');
|
||||
|
||||
// remove /./ and /../ where possible
|
||||
$uri = str_replace('/./', '/', $uri);
|
||||
// inspired by patch from Oleg Cherniy
|
||||
do {
|
||||
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, -1, $changed);
|
||||
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, 1, $changed);
|
||||
} while ($changed);
|
||||
|
||||
self::$debugText .= "traversals removed : {$uri}\n\n";
|
||||
@@ -249,20 +251,19 @@ class Minify_CSS_UriRewriter {
|
||||
return $uri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get realpath with any trailing slash removed
|
||||
* Get realpath with any trailing slash removed. If realpath() fails,
|
||||
* just remove the trailing slash.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return mixed real path or false on realpath() failure
|
||||
* @return mixed path with no trailing slash
|
||||
*/
|
||||
protected static function _realpath($path)
|
||||
{
|
||||
$path = realpath($path);
|
||||
if (! $path) {
|
||||
return false;
|
||||
$realPath = realpath($path);
|
||||
if ($realPath !== false) {
|
||||
$path = $realPath;
|
||||
}
|
||||
$last = $path[strlen($path) - 1];
|
||||
return ($last === '/' || $last === '\\')
|
||||
|
@@ -143,12 +143,12 @@ class Minify_ImportProcessor {
|
||||
// strip doc root
|
||||
$path = substr($path, strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
|
||||
// fix to absolute URL
|
||||
$url = strtr($path, DIRECTORY_SEPARATOR, '/');
|
||||
$url = strtr($path, '/\\', '//');
|
||||
// remove /./ and /../ where possible
|
||||
$url = str_replace('/./', '/', $url);
|
||||
// inspired by patch from Oleg Cherniy
|
||||
do {
|
||||
$url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, -1, $changed);
|
||||
$url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, 1, $changed);
|
||||
} while ($changed);
|
||||
}
|
||||
}
|
||||
|
@@ -8,11 +8,9 @@ function test_Minify_CSS_UriRewriter()
|
||||
{
|
||||
global $thisDir;
|
||||
|
||||
Minify_CSS_UriRewriter::$debugText = '';
|
||||
$in = file_get_contents($thisDir . '/_test_files/css_uriRewriter/in.css');
|
||||
$expected = file_get_contents($thisDir . '/_test_files/css_uriRewriter/exp.css');
|
||||
|
||||
Minify_CSS_UriRewriter::$debugText = '';
|
||||
|
||||
$actual = Minify_CSS_UriRewriter::rewrite(
|
||||
$in
|
||||
,$thisDir . '/_test_files/css_uriRewriter' // currentDir
|
||||
@@ -31,6 +29,28 @@ function test_Minify_CSS_UriRewriter()
|
||||
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n"
|
||||
, Minify_CSS_UriRewriter::$debugText;
|
||||
}
|
||||
|
||||
Minify_CSS_UriRewriter::$debugText = '';
|
||||
$in = '../../../../assets/skins/sam/sprite.png';
|
||||
$exp = '/yui/assets/skins/sam/sprite.png';
|
||||
$actual = Minify_CSS_UriRewriter::rewriteRelative(
|
||||
$in
|
||||
,'sf_root_dir\web\yui\menu\assets\skins\sam'
|
||||
,'sf_root_dir\web'
|
||||
);
|
||||
|
||||
$passed = assertTrue($exp === $actual, 'Minify_CSS_UriRewriter : Issue 99');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Input:\n\n{$in}\n";
|
||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($exp). " bytes\n\n{$exp}\n\n\n";
|
||||
}
|
||||
|
||||
// show debugging only when test run directly
|
||||
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n"
|
||||
, Minify_CSS_UriRewriter::$debugText;
|
||||
}
|
||||
}
|
||||
|
||||
test_Minify_CSS_UriRewriter();
|
Reference in New Issue
Block a user