Skip to content

Commit

Permalink
fix(issue:3767) variable values with periods
Browse files Browse the repository at this point in the history
* Fix issue with variable values with periods when unquoted by single or
  double quotes.
  • Loading branch information
puckowski committed Dec 14, 2024
1 parent 304c310 commit 70d0936
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,9 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
value = this.permissiveValue(/[;}]/);
}
}
else if (isVariable) {
value = this.variableValue();
}
// Try to store values as anonymous
// If we need the value later we'll re-parse it in ruleset.parseValue
else {
Expand Down Expand Up @@ -1638,6 +1641,18 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
parserInput.restore();
}
},
variableValue: function () {
let match = this.anonymousValue();
if (match) {
return match;
} else {
const index = parserInput.i;
match = parserInput.$re(/^([^#@$+/'"*`(;{}-]*);|(^[(?!.*\n)^.#@$+/'"*`(;{}-]*)(["'])((?!.*@.*)(?<!.*@.*).+?)\1;/);
if (match) {
return new(tree.Anonymous)(match[0].slice(0, -1), index + currentIndex);
}
}
},
anonymousValue: function () {
const index = parserInput.i;
const match = parserInput.$re(/^([^.#@$+/'"*`(;{}-]*);/);
Expand Down
9 changes: 9 additions & 0 deletions packages/test-data/css/_main/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@
.radio_checked {
border-color: #fff;
}
.mixed {
m-1: "a.hello";
m-2: 'a';
m-3: 'a' a a "a.";
m-4: a "a-" a "abc";
m-5: a "a.ab" c c 'a.bc' abc d;
m-6: a.hello;
m-7: 'a.b' "abc" abc a.b.c 'a.b.c';
}
18 changes: 18 additions & 0 deletions packages/test-data/less/_main/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,21 @@
.@{radio-cls-checked} {
border-color: #fff;
}

@doubleQuoted: "a.hello";
@quoted: 'a';
@mixedOne: 'a' a a "a.";
@mixedTwo: a "a-" a "abc";
@mixedThree: a "a.ab" c c 'a.bc' abc d;
@mixedFour: a.hello;
@mixedFive: 'a.b' "abc" abc a.b.c 'a.b.c';

.mixed {
m-1: @doubleQuoted;
m-2: @quoted;
m-3: @mixedOne;
m-4: @mixedTwo;
m-5: @mixedThree;
m-6: @mixedFour;
m-7: @mixedFive;
}

0 comments on commit 70d0936

Please sign in to comment.