Skip to content

Commit

Permalink
Less_Tree_Color: Fix "Undefined property" warning for $value
Browse files Browse the repository at this point in the history
This is accessed from Less_Tree_Variable when compiling a variable
variable name (e.g. `@@example`) where the inner value is a string that
happens to also be a color keyword.

Bug: T352830
Change-Id: I3e5b6daeefa4f0528464a479dc790d0e10f28b02
  • Loading branch information
Hannah Okwelum authored and Krinkle committed Dec 13, 2023
1 parent 9fad91e commit b01ecdd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
11 changes: 8 additions & 3 deletions lib/Less/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,20 @@ private function parseEntitiesKeyword() {

// duplicate of Less_Tree_Color::FromKeyword
private function FromKeyword( $keyword ) {
$keyword = strtolower( $keyword );
$c = $keyword = strtolower( $keyword );

if ( Less_Colors::hasOwnProperty( $keyword ) ) {
// detect named color
return new Less_Tree_Color( substr( Less_Colors::color( $keyword ), 1 ) );
$c = new Less_Tree_Color( substr( Less_Colors::color( $keyword ), 1 ) );
}

if ( $keyword === 'transparent' ) {
return new Less_Tree_Color( [ 0, 0, 0 ], 0, true );
$c = new Less_Tree_Color( [ 0, 0, 0 ], 0, true );
}

if ( isset( $c ) && is_object( $c ) ) {
$c->value = $keyword;
return $c;
}
}

Expand Down
12 changes: 9 additions & 3 deletions lib/Less/Tree/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Less_Tree_Color extends Less_Tree {
public $rgb;
public $alpha;
public $isTransparentKeyword;
public $value;

public function __construct( $rgb, $a = 1, $isTransparentKeyword = null ) {
if ( $isTransparentKeyword ) {
Expand Down Expand Up @@ -213,15 +214,20 @@ public function toHex( $v ) {
* @param string $keyword
*/
public static function fromKeyword( $keyword ) {
$keyword = strtolower( $keyword );
$c = $keyword = strtolower( $keyword );

if ( Less_Colors::hasOwnProperty( $keyword ) ) {
// detect named color
return new self( substr( Less_Colors::color( $keyword ), 1 ) );
$c = new self( substr( Less_Colors::color( $keyword ), 1 ) );
}

if ( $keyword === 'transparent' ) {
return new self( [ 0, 0, 0 ], 0, true );
$c = new self( [ 0, 0, 0 ], 0, true );
}

if ( isset( $c ) && is_object( $c ) ) {
$c->value = $keyword;
return $c;
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/phpunit/FixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class phpunit_FixturesTest extends phpunit_bootstrap {
'mixins' => true,

// Temporary disabled; Bug logged here T352830
// If T352866 is fixed, this is should also be resolved
'variables' => true,
'functions' => true, // resolved if T352830 is fixed;

// Temporary disabled; Bug logged here T353289
'functions' => true,

// Temporary disabled; Bug logged here T352859
'selectors' => true,
Expand Down

0 comments on commit b01ecdd

Please sign in to comment.