mirror of
https://github.com/mrclay/minify.git
synced 2025-08-29 16:49:47 +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";
|
self::$debugText .= "docroot stripped : {$path}\n";
|
||||||
|
|
||||||
// fix to root-relative URI
|
// fix to root-relative URI
|
||||||
$uri = strtr($path, DIRECTORY_SEPARATOR, '/');
|
|
||||||
|
$uri = strtr($path, '/\\', '//');
|
||||||
|
|
||||||
// remove /./ and /../ where possible
|
// remove /./ and /../ where possible
|
||||||
$uri = str_replace('/./', '/', $uri);
|
$uri = str_replace('/./', '/', $uri);
|
||||||
// inspired by patch from Oleg Cherniy
|
// inspired by patch from Oleg Cherniy
|
||||||
do {
|
do {
|
||||||
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, -1, $changed);
|
$uri = preg_replace('@/[^/]+/\\.\\./@', '/', $uri, 1, $changed);
|
||||||
} while ($changed);
|
} while ($changed);
|
||||||
|
|
||||||
self::$debugText .= "traversals removed : {$uri}\n\n";
|
self::$debugText .= "traversals removed : {$uri}\n\n";
|
||||||
@@ -249,20 +251,19 @@ class Minify_CSS_UriRewriter {
|
|||||||
return $uri;
|
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
|
* @param string $path
|
||||||
*
|
*
|
||||||
* @return mixed real path or false on realpath() failure
|
* @return mixed path with no trailing slash
|
||||||
*/
|
*/
|
||||||
protected static function _realpath($path)
|
protected static function _realpath($path)
|
||||||
{
|
{
|
||||||
$path = realpath($path);
|
$realPath = realpath($path);
|
||||||
if (! $path) {
|
if ($realPath !== false) {
|
||||||
return false;
|
$path = $realPath;
|
||||||
}
|
}
|
||||||
$last = $path[strlen($path) - 1];
|
$last = $path[strlen($path) - 1];
|
||||||
return ($last === '/' || $last === '\\')
|
return ($last === '/' || $last === '\\')
|
||||||
|
@@ -143,12 +143,12 @@ class Minify_ImportProcessor {
|
|||||||
// strip doc root
|
// strip doc root
|
||||||
$path = substr($path, strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
|
$path = substr($path, strlen(realpath($_SERVER['DOCUMENT_ROOT'])));
|
||||||
// fix to absolute URL
|
// fix to absolute URL
|
||||||
$url = strtr($path, DIRECTORY_SEPARATOR, '/');
|
$url = strtr($path, '/\\', '//');
|
||||||
// remove /./ and /../ where possible
|
// remove /./ and /../ where possible
|
||||||
$url = str_replace('/./', '/', $url);
|
$url = str_replace('/./', '/', $url);
|
||||||
// inspired by patch from Oleg Cherniy
|
// inspired by patch from Oleg Cherniy
|
||||||
do {
|
do {
|
||||||
$url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, -1, $changed);
|
$url = preg_replace('@/[^/]+/\\.\\./@', '/', $url, 1, $changed);
|
||||||
} while ($changed);
|
} while ($changed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,12 +7,10 @@ require_once 'Minify/CSS/UriRewriter.php';
|
|||||||
function test_Minify_CSS_UriRewriter()
|
function test_Minify_CSS_UriRewriter()
|
||||||
{
|
{
|
||||||
global $thisDir;
|
global $thisDir;
|
||||||
|
|
||||||
|
Minify_CSS_UriRewriter::$debugText = '';
|
||||||
$in = file_get_contents($thisDir . '/_test_files/css_uriRewriter/in.css');
|
$in = file_get_contents($thisDir . '/_test_files/css_uriRewriter/in.css');
|
||||||
$expected = file_get_contents($thisDir . '/_test_files/css_uriRewriter/exp.css');
|
$expected = file_get_contents($thisDir . '/_test_files/css_uriRewriter/exp.css');
|
||||||
|
|
||||||
Minify_CSS_UriRewriter::$debugText = '';
|
|
||||||
|
|
||||||
$actual = Minify_CSS_UriRewriter::rewrite(
|
$actual = Minify_CSS_UriRewriter::rewrite(
|
||||||
$in
|
$in
|
||||||
,$thisDir . '/_test_files/css_uriRewriter' // currentDir
|
,$thisDir . '/_test_files/css_uriRewriter' // currentDir
|
||||||
@@ -30,7 +28,29 @@ function test_Minify_CSS_UriRewriter()
|
|||||||
// show debugging only when test run directly
|
// show debugging only when test run directly
|
||||||
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n"
|
echo "--- Minify_CSS_UriRewriter::\$debugText\n\n"
|
||||||
, Minify_CSS_UriRewriter::$debugText;
|
, 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();
|
test_Minify_CSS_UriRewriter();
|
Reference in New Issue
Block a user