Permalink
Browse files

realpath replaced with custom implementation which does not resolve s…

…ymlinks
  • Loading branch information...
1 parent 180fb3f commit c551ab789eeb39bbc8d74eef3558b5f0e7330f2f @janmarek committed Nov 27, 2012
Showing with 41 additions and 7 deletions.
  1. +1 −1 WebLoader/Compiler.php
  2. +9 −4 WebLoader/FileCollection.php
  3. +2 −2 WebLoader/Filter/CssUrlsFilter.php
  4. +29 −0 WebLoader/Path.php
View
2 WebLoader/Compiler.php
@@ -75,7 +75,7 @@ public function getOutputDir()
*/
public function setOutputDir($tempPath)
{
- $tempPath = realpath($tempPath);
+ $tempPath = Path::normalize($tempPath);
if (!is_dir($tempPath)) {
throw new FileNotFoundException('Temp path does not exist.');
View
13 WebLoader/FileCollection.php
@@ -44,11 +44,16 @@ public function getFiles()
*/
public function cannonicalizePath($path)
{
- $rel = realpath($this->root . "/" . $path);
- if ($rel !== false) return $rel;
- $abs = realpath($path);
- if ($abs !== false) return $abs;
+ $rel = Path::normalize($this->root . "/" . $path);
+ if (file_exists($rel)) {
+ return $rel;
+ }
+
+ $abs = Path::normalize($path);
+ if (file_exists($abs)) {
+ return $abs;
+ }
throw new FileNotFoundException("File '$path' does not exist.");
}
View
4 WebLoader/Filter/CssUrlsFilter.php
@@ -23,7 +23,7 @@ class CssUrlsFilter
*/
public function __construct($docRoot, $basePath = '/')
{
- $this->docRoot = realpath($docRoot);
+ $this->docRoot = \WebLoader\Path::normalize($docRoot);
if (!is_dir($this->docRoot)) {
throw new \WebLoader\InvalidArgumentException('Given document root is not directory.');
@@ -46,7 +46,7 @@ public function absolutizeUrl($url, $quote, $cssFile)
return $url;
}
- $cssFile = realpath($cssFile);
+ $cssFile = \WebLoader\Path::normalize($cssFile);
// inside document root
if (strncmp($cssFile, $this->docRoot, strlen($this->docRoot)) === 0) {
View
29 WebLoader/Path.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace WebLoader;
+
+class Path
+{
+
+ public static function normalize($path)
+ {
+ $path = strtr($path, '\\', '/');
+ $root = ($path[0] === '/') ? '/' : '';
+ $pieces = explode('/', trim($path, '/'));
+ $res = array();
+
+ foreach ($pieces as $piece) {
+ if ($piece === '.' || empty($piece)) {
+ continue;
+ }
+ if ($piece === '..') {
+ array_pop($res);
+ } else {
+ array_push($res, $piece);
+ }
+ }
+
+ return $root . implode('/', $res);
+ }
+
+}

0 comments on commit c551ab7

Please sign in to comment.