From 02560ebc1094aa488297e0d25906c84fc3d0a0f8 Mon Sep 17 00:00:00 2001 From: b-kelly Date: Wed, 9 Mar 2022 15:57:37 -0500 Subject: [PATCH] fix(parser): fix crash when css variable property does not end with a semicolon Fixes #3698 #3373 --- packages/less/src/less/parser/parser.js | 2 +- packages/test-data/css/_main/permissive-parse.css | 9 +++++++++ packages/test-data/less/_main/permissive-parse.less | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js index c7a65cb07..9e46aed4b 100644 --- a/packages/less/src/less/parser/parser.js +++ b/packages/less/src/less/parser/parser.js @@ -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 diff --git a/packages/test-data/css/_main/permissive-parse.css b/packages/test-data/css/_main/permissive-parse.css index 58eb55e60..d54021541 100644 --- a/packages/test-data/css/_main/permissive-parse.css +++ b/packages/test-data/css/_main/permissive-parse.css @@ -35,3 +35,12 @@ foo[attr="blah"] { --value: a /* { ; } */; --comment-within: ( /* okay?; comment; */ ); } +.test-no-trailing-semicolon { + --value: foo; +} +.test-no-trailing-semicolon2 { + --value: foo; +} +.test-no-trailing-semicolon3 { + --value: foo; +} diff --git a/packages/test-data/less/_main/permissive-parse.less b/packages/test-data/less/_main/permissive-parse.less index 67b1b4211..a4c09bf31 100644 --- a/packages/test-data/less/_main/permissive-parse.less +++ b/packages/test-data/less/_main/permissive-parse.less @@ -47,4 +47,9 @@ .test-rule-comment { --value: a/* { ; } */; --comment-within: ( /* okay?; comment; */ ); -} \ No newline at end of file +} +.test-no-trailing-semicolon { + --value: foo +} +.test-no-trailing-semicolon2 {--value: foo} +.test-no-trailing-semicolon3 { --value: foo }