Skip to content

Commit

Permalink
fix(parser): fix crash when css variable property does not end with a…
Browse files Browse the repository at this point in the history
… semicolon

Fixes less#3698 less#3373
  • Loading branch information
b-kelly committed Mar 9, 2022
1 parent 3f05b5c commit 4a22782
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/less/src/less-browser/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function extractId(href) {
}

export function addDataAttr(options, tag) {
if(!tag) return; // in case of tag is null or undefined
if (!tag) {return;} // in case of tag is null or undefined
for (const opt in tag.dataset) {
if (tag.dataset.hasOwnProperty(opt)) {
if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
Expand Down
2 changes: 1 addition & 1 deletion packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ const Parser = function Parser(context, imports, fileInfo) {

// Custom property values get permissive parsing
if (name[0].value && name[0].value.slice(0, 2) === '--') {
value = this.permissiveValue();
value = this.permissiveValue(/[;}]/);
}
// Try to store values as anonymous
// If we need the value later we'll re-parse it in ruleset.parseValue
Expand Down
9 changes: 9 additions & 0 deletions packages/test-data/css/_main/permissive-parse.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ foo[attr="blah"] {
--value: a /* { ; } */;
--comment-within: ( /* okay?; comment; */ );
}
.test-no-trailing-semicolon {
--value: blue;
}
.test-no-trailing-semicolon2 {
--value: blue;
}
.test-no-trailing-semicolon3 {
--value: blue;
}
7 changes: 6 additions & 1 deletion packages/test-data/less/_main/permissive-parse.less
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@
.test-rule-comment {
--value: a/* { ; } */;
--comment-within: ( /* okay?; comment; */ );
}
}
.test-no-trailing-semicolon {
--value: blue
}
.test-no-trailing-semicolon2 {--value: blue}
.test-no-trailing-semicolon3 { --value: blue }

0 comments on commit 4a22782

Please sign in to comment.