From f4e6976af24a8e4599cca4d89073bd047b75641c Mon Sep 17 00:00:00 2001 From: Chris Keers Date: Tue, 23 Oct 2018 00:50:48 -0600 Subject: [PATCH 1/3] Added patch for CSS named grids This adds a patch to lessc->compile that adds a protection to CSS named grids. Once all other parsing is done successfully the protection is removed and the compiled CSS returned. The protection is a rough patch that removes brackets and replaces them with 3 underscores so [grid-name] becomes ___grid-name___ which does not trigger any parser errors allowing everything to be parsed as normal. If this patch is added into lessphp permanently I would suggest doing 4 underscores for (paranoia) safeties sake or a different pattern that is still safe to parse but less common to be used in someones code. --- lessc.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lessc.inc.php b/lessc.inc.php index 37988952..b451eda5 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -1988,6 +1988,8 @@ public function __construct($fname = null) { } public function compile($string, $name = null) { + $string = preg_replace('/\[([\w-]+)\]/', '___$1___', $string); // Protect CSS named grids + $locale = setlocale(LC_NUMERIC, 0); setlocale(LC_NUMERIC, "C"); @@ -2010,6 +2012,7 @@ public function compile($string, $name = null) { $this->formatter->block($this->scope); $out = ob_get_clean(); setlocale(LC_NUMERIC, $locale); + $out = preg_replace('/___([\w-]+)___/', '[$1]', $out); // Remove CSS named grid protections return $out; } From bab0122aa8be6f9b70ca73c23b7cbed873fe4987 Mon Sep 17 00:00:00 2001 From: Chris Keers Date: Tue, 23 Oct 2018 12:13:07 -0600 Subject: [PATCH 2/3] Patch to allow CSS named grids: imported files This is an additional patch to allow lessphp to compile CSS named grids from imported files. --- lessc.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lessc.inc.php b/lessc.inc.php index b451eda5..374547d9 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -2452,6 +2452,7 @@ public function __construct($lessc, $sourceName = null) { } public function parse($buffer) { + $buffer = preg_replace('/\[([\w-]+)\]/', '___$1___', $buffer); // Protect CSS named grids $this->count = 0; $this->line = 1; From c3b83a86e6aea976fda0ebcdc0b06ede17f23565 Mon Sep 17 00:00:00 2001 From: Chris Keers Date: Tue, 23 Oct 2018 12:39:05 -0600 Subject: [PATCH 3/3] Patch for CSS named grids. This patch protects CSS named grids by replacing the brackets before any parsing or compiling happens. Once all parsing and compiling is done the brackets are replaced. NOTE: Brackets are changed to 3 underscores which works great but has a small chance of clashing with someones code, in this case I would suggest changing it to 4 underscores. Who is writing that many in their less/ css? --- lessc.inc.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lessc.inc.php b/lessc.inc.php index 374547d9..dcd33295 100644 --- a/lessc.inc.php +++ b/lessc.inc.php @@ -1,5 +1,4 @@ compile() will handle unprotecting CSS named grids. $buffer = preg_replace('/\[([\w-]+)\]/', '___$1___', $buffer); // Protect CSS named grids $this->count = 0; $this->line = 1;