Skip to content

Commit

Permalink
Merge "Less_Functions: Fix unquoted passed to color()"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 11, 2024
2 parents 10c935c + 44b03fb commit 4aee1a7
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/Less/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,20 +761,24 @@ public function percentage( $n ) {
return new Less_Tree_Dimension( $n->value * 100, '%' );
}

public function color( $n ) {
if ( $n instanceof Less_Tree_Quoted ) {
$colorCandidate = $n->value;
$returnColor = Less_Tree_Color::fromKeyword( $colorCandidate );
if ( $returnColor ) {
return $returnColor;
}
if ( preg_match( '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/', $colorCandidate ) ) {
return new Less_Tree_Color( substr( $colorCandidate, 1 ) );
}
throw new Less_Exception_Compiler( "argument must be a color keyword or 3/6 digit hex e.g. #FFF" );
} else {
throw new Less_Exception_Compiler( "argument must be a string" );
/**
* @see less-2.5.3.js#colorFunctions.color
* @param Less_Tree_Quoted|Less_Tree_Color|Less_Tree_Keyword $c
* @return Less_Tree_Color
*/
public function color( $c ) {
if ( ( $c instanceof Less_Tree_Quoted ) &&
preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})/', $c->value )
) {
return new Less_Tree_Color( substr( $c->value, 1 ) );
}

if ( ( $c instanceof Less_Tree_Color ) || ( $c = Less_Tree_Color::fromKeyword( $c->value ) ) ) {
$c->value = null;
return $c;
}

throw new Less_Exception_Compiler( "argument must be a color keyword or 3/6 digit hex e.g. #FFF" );
}

public function iscolor( $n ) {
Expand Down

0 comments on commit 4aee1a7

Please sign in to comment.