Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 4a22782

Browse files
committed
fix(parser): fix crash when css variable property does not end with a semicolon
Fixes less#3698 less#3373
1 parent 3f05b5c commit 4a22782

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

packages/less/src/less-browser/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function extractId(href) {
99
}
1010

1111
export function addDataAttr(options, tag) {
12-
if(!tag) return; // in case of tag is null or undefined
12+
if (!tag) {return;} // in case of tag is null or undefined
1313
for (const opt in tag.dataset) {
1414
if (tag.dataset.hasOwnProperty(opt)) {
1515
if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {

packages/less/src/less/parser/parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ const Parser = function Parser(context, imports, fileInfo) {
15411541

15421542
// Custom property values get permissive parsing
15431543
if (name[0].value && name[0].value.slice(0, 2) === '--') {
1544-
value = this.permissiveValue();
1544+
value = this.permissiveValue(/[;}]/);
15451545
}
15461546
// Try to store values as anonymous
15471547
// If we need the value later we'll re-parse it in ruleset.parseValue

packages/test-data/css/_main/permissive-parse.css

+9
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ foo[attr="blah"] {
3535
--value: a /* { ; } */;
3636
--comment-within: ( /* okay?; comment; */ );
3737
}
38+
.test-no-trailing-semicolon {
39+
--value: blue;
40+
}
41+
.test-no-trailing-semicolon2 {
42+
--value: blue;
43+
}
44+
.test-no-trailing-semicolon3 {
45+
--value: blue;
46+
}

packages/test-data/less/_main/permissive-parse.less

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@
4747
.test-rule-comment {
4848
--value: a/* { ; } */;
4949
--comment-within: ( /* okay?; comment; */ );
50-
}
50+
}
51+
.test-no-trailing-semicolon {
52+
--value: blue
53+
}
54+
.test-no-trailing-semicolon2 {--value: blue}
55+
.test-no-trailing-semicolon3 { --value: blue }

0 commit comments

Comments
 (0)