From d486041837b01d60a56abd2ec35cbe41e056d950 Mon Sep 17 00:00:00 2001 From: Jim Dalton Date: Mon, 12 Mar 2012 21:53:13 -0700 Subject: [PATCH 1/2] Rework fileExists() to handle complex relative path and symlinked folder structures --- lessc.inc.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lessc.inc.php b/lessc.inc.php index f86dc9d7..cbc779bf 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -324,8 +324,8 @@ function fixTags($tags) { function findImport($url) { foreach ((array)$this->importDir as $dir) { $full = $dir.(substr($dir, -1) != '/' ? '/' : '').$url; - if ($this->fileExists($file = $full.'.less') || $this->fileExists($file = $full)) { - return $file; + if (($path = $this->fileExists($full.'.less')) || ($path = $this->fileExists($full))) { + return $path; } } @@ -333,8 +333,18 @@ function findImport($url) { } function fileExists($name) { + if (file_exists($name)) { + return $name; + } + // sym link workaround - return file_exists($name) || file_exists(realpath(preg_replace('/\w+\/\.\.\//', '', $name))); + $pattern = '/([^.][^\/]*\/|\.[^.][^\/]*\/|\.[^.][^\/]*\/)\.\.\//'; + while (preg_match($pattern, $name, $matches)) { + $name = preg_replace($pattern, '/', $name); + } + if (file_exists(realpath($name))) { + return realpath($name); + } } // a list of expressions From 07f995ed4a0aebe14108c408081d0c1117a0a76a Mon Sep 17 00:00:00 2001 From: Jim Dalton Date: Mon, 12 Mar 2012 22:13:47 -0700 Subject: [PATCH 2/2] Fix miscopied regex --- lessc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lessc.inc.php b/lessc.inc.php index cbc779bf..75645c5c 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -338,7 +338,7 @@ function fileExists($name) { } // sym link workaround - $pattern = '/([^.][^\/]*\/|\.[^.][^\/]*\/|\.[^.][^\/]*\/)\.\.\//'; + $pattern = '/([^.][^\/]*\/|\.[^.\/][^\/]*\/|\.\.[^\/]+\/)\.\.\//'; while (preg_match($pattern, $name, $matches)) { $name = preg_replace($pattern, '/', $name); }