From 21e77ca4ffe657fe429d92bc71a07a8c91a3a381 Mon Sep 17 00:00:00 2001 From: Hannah Okwelum Date: Mon, 29 Jan 2024 16:39:55 +0100 Subject: [PATCH] Fix interpolated selector & String interpolation string interpolation should run in a loop as long as the string keeps being modified see https://github.com/less/less.js/commit/796d37cc663a6f940b4e2cb9191628284f6f0bed Bug: T353142 Change-Id: I9eae221cbb3fe93b17d79a66e9b3425cbe24163b --- lib/Less/Tree/Quoted.php | 21 ++++++++++++--------- lib/Less/Tree/Selector.php | 9 ++++----- test/phpunit/FixturesTest.php | 5 +---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/Less/Tree/Quoted.php b/lib/Less/Tree/Quoted.php index 2b67e868..b78b85e5 100644 --- a/lib/Less/Tree/Quoted.php +++ b/lib/Less/Tree/Quoted.php @@ -45,17 +45,20 @@ public function compile( $env ) { $value = str_replace( $matches[0][$i], $js, $value ); } } - - if ( preg_match_all( '/@\{([\w-]+)\}/', $value, $matches ) ) { - foreach ( $matches[1] as $i => $match ) { - $v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo ); - $v = $v->compile( $env ); - $v = ( $v instanceof self ) ? $v->value : $v->toCSS(); - $value = str_replace( $matches[0][$i], $v, $value ); + $r = $value; + do{ + $value = $r; + if ( preg_match_all( '/@\{([\w-]+)\}/', $value, $matches ) ) { + foreach ( $matches[1] as $i => $match ) { + $v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo ); + $v = $v->compile( $env ); + $v = ( $v instanceof self ) ? $v->value : $v->toCSS(); + $r = str_replace( $matches[0][$i], $v, $r ); + } } - } + }while ( $r != $value ); - return new self( $this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo ); + return new self( $this->quote . $r . $this->quote, $r, $this->escaped, $this->index, $this->currentFileInfo ); } public function compare( $x ) { diff --git a/lib/Less/Tree/Selector.php b/lib/Less/Tree/Selector.php index d1307a56..64390542 100644 --- a/lib/Less/Tree/Selector.php +++ b/lib/Less/Tree/Selector.php @@ -101,14 +101,13 @@ public function CacheElements() { $css .= $v->value; continue; } - - if ( - ( $v->value instanceof Less_Tree_Selector || $v->value instanceof Less_Tree_Variable ) + if ( ( $v->value instanceof Less_Tree_Selector || $v->value instanceof Less_Tree_Variable ) || !is_string( $v->value->value ) ) { $this->cacheable = false; - return; } - $css .= $v->value->value; + if ( isset( $v->value->value ) && !is_object( $v->value->value ) ) { + $css .= $v->value->value; + } } $this->_oelements_len = preg_match_all( '/[,&#\*\.\w-](?:[\w-]|(?:\\\\.))*/', $css, $matches ); diff --git a/test/phpunit/FixturesTest.php b/test/phpunit/FixturesTest.php index 93375c3b..aff8e049 100644 --- a/test/phpunit/FixturesTest.php +++ b/test/phpunit/FixturesTest.php @@ -41,8 +41,7 @@ class phpunit_FixturesTest extends phpunit_bootstrap { 'css-3' => true, 'import-reference' => true, - // Temporary disabled; Bug logged T353133 - 'strings' => true, + // TODO; Create Task for import-interpolation 'import-interpolation' => true, // Temporary disabled; Bug logged here T352897 @@ -73,8 +72,6 @@ class phpunit_FixturesTest extends phpunit_bootstrap { // behaviour of doing maths in parentheses by default 'parens' => true, - // Temporary disabled; Bug logged T353142 - 'mixins-interpolated' => true, // Temporary disabled; Bug logged T353143 'detached-rulesets' => true, ]