From 49ac30763ad8a3cfe2e2e6d3ae6b91520241191a Mon Sep 17 00:00:00 2001 From: Mario Campa Date: Thu, 6 Apr 2017 13:03:17 -0700 Subject: [PATCH 1/2] Fix issue with realpath and php stream wrapper paths (ex. assets://scss/file.scss) --- src/Compiler.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Compiler.php b/src/Compiler.php index 68003b90..ccea71ba 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -3226,7 +3226,7 @@ public function getVariables() public function addParsedFile($path) { if (isset($path) && file_exists($path)) { - $this->parsedFiles[realpath($path)] = filemtime($path); + $this->parsedFiles[$this->realPath($path)] = filemtime($path); } } @@ -3351,7 +3351,7 @@ public function addFeature($name) protected function importFile($path, $out) { // see if tree is cached - $realPath = realpath($path); + $realPath = $this->realPath($path); if (isset($this->importCache[$realPath])) { $this->handleImportLoop($realPath); @@ -3371,6 +3371,28 @@ protected function importFile($path, $out) array_shift($this->importPaths); } + /** + * Return canonicalized path + * + * @param string $path + * + * @return string|null + */ + protected function realPath($path) + { + $path = explode(DIRECTORY_SEPARATOR, $path); + $keys = array_keys($path, '..'); + + foreach($keys AS $keypos => $key) + { + array_splice($path, $key - ($keypos * 2 + 1), 2); + } + + $path = implode(DIRECTORY_SEPARATOR, $path); + + return str_replace('.' . DIRECTORY_SEPARATOR, '', $path); + } + /** * Return the file path for an import url if it exists * @@ -3482,7 +3504,7 @@ protected function handleImportLoop($name) for ($env = $this->env; $env; $env = $env->parent) { $file = $this->sourceNames[$env->block->sourceIndex]; - if (realpath($file) === $name) { + if ($this->realPath($file) === $name) { $this->throwError('An @import loop has been found: %s imports %s', $file, basename($file)); break; } From 23ad29c1cd0ffb5d80e355966a8083c264264f36 Mon Sep 17 00:00:00 2001 From: Mario Campa Date: Sun, 4 Nov 2018 19:36:41 -0800 Subject: [PATCH 2/2] fix php 7.2 warning --- src/Node/Number.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Node/Number.php b/src/Node/Number.php index d4f406fa..976c8051 100644 --- a/src/Node/Number.php +++ b/src/Node/Number.php @@ -266,33 +266,26 @@ public function unitStr() public function output(Compiler $compiler = null) { $dimension = round($this->dimension, static::$precision); - $units = array_filter($this->units, function ($unitSize) { return $unitSize; }); - if (count($units) > 1 && array_sum($units) === 0) { $dimension = $this->dimension; $units = []; - $this->normalizeUnits($dimension, $units, 'in'); - $dimension = round($dimension, static::$precision); $units = array_filter($units, function ($unitSize) { return $unitSize; }); } - $unitSize = array_sum($units); - if ($compiler && ($unitSize > 1 || $unitSize < 0 || count($units) > 1)) { $compiler->throwError((string) $dimension . $this->unitStr() . " isn't a valid CSS value."); } - reset($units); - list($unit, ) = each($units); - - return (string) $dimension . $unit; + $unit = key($units); + $dimension = number_format($dimension, static::$precision, '.', ''); + return (static::$precision ? rtrim(rtrim($dimension, '0'), '.') : $dimension) . $unit; } /**