Skip to content

Commit 3a8e5ed

Browse files
Krinklejenkins-bot
authored andcommitted
Fix interpolation of string with number followed by underscore
This was fixed upstream in Less.js v2.6.0. I caught this during a review of the nearby parseEntitiesDimension as part of T403056. Remove the unneeded "@" silence operator from the ord() call. This was added in 2013 with commit 51e29cb to deal with null when the position has reached outside the bounds of $this->input. A better fix was added in Ie8d5da3ed4 (67807cb) using `?? ''`, which removes the need for error silencing, because it is now always passed a string. Ref less/less.js#2462 Ref oyejorge#293 Change-Id: I968056b7e45c9752b8ce3833979729ac8230dc6d
1 parent cd0ab1e commit 3a8e5ed

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/Less/Parser.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,7 @@ private function parseEntitiesPropertyCurly() {
15541554
* `rgb` and `hsl` colors are parsed through the `entities.call` parser.
15551555
*
15561556
* @return Less_Tree_Color|null
1557+
* @see less-3.13.1.js#parsers.entities.color
15571558
*/
15581559
private function parseEntitiesColor() {
15591560
$this->save();
@@ -1573,21 +1574,24 @@ private function parseEntitiesColor() {
15731574
* 0.5em 95%
15741575
*
15751576
* @return Less_Tree_Dimension|null
1577+
* @see less-3.13.1.js#parsers.entities.dimension
15761578
*/
15771579
private function parseEntitiesDimension() {
1578-
$c = @ord( $this->input[$this->pos] ?? '' );
1579-
1580+
// Optimization: Inlined version of Less.js parserInput.peekNotNumeric
1581+
static $CHARCODE_COMMA = 44;
1582+
static $CHARCODE_FORWARD_SLASH = 47;
1583+
static $CHARCODE_PLUS = 43;
1584+
static $CHARCODE_9 = 57;
1585+
$c = ord( $this->input[$this->pos] ?? '' );
15801586
// Is the first char of the dimension 0-9, '.', '+' or '-'
1581-
if ( ( $c > 57 || $c < 43 ) || $c === 47 || $c == 44 ) {
1587+
$peekNotNumeric = ( $c > $CHARCODE_9 || $c < $CHARCODE_PLUS ) || $c === $CHARCODE_FORWARD_SLASH || $c === $CHARCODE_COMMA;
1588+
1589+
if ( $peekNotNumeric ) {
15821590
return;
15831591
}
1584-
1585-
$value = $this->matchReg( '/\\G([+-]?\d*\.?\d+)(%|[a-z]+)?/i' );
1592+
$value = $this->matchReg( '/\\G([+-]?\d*\.?\d+)(%|[a-z_]+)?/i' );
15861593
if ( $value ) {
1587-
if ( isset( $value[2] ) ) {
1588-
return new Less_Tree_Dimension( $value[1], $value[2] );
1589-
}
1590-
return new Less_Tree_Dimension( $value[1] );
1594+
return new Less_Tree_Dimension( $value[1], $value[2] ?? null );
15911595
}
15921596
}
15931597

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.icon-5_large {
2+
background-image: url(/img/icon/5_large.svg);
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// https://github.com/less/less.js/issues/2462
2+
@type: 5_large;
3+
4+
.icon-@{type} {
5+
background-image: ~"url(/img/icon/@{type}.svg)";
6+
}

0 commit comments

Comments
 (0)