Skip to content

Commit d93592f

Browse files
lightman76NV
authored andcommitted
Added fix for handling of spaces within parenthesis in values. (NV#87)
Added fix for handling of spaces within parenthesis in values. Also added handling of nested parenthesis in a value so that it doesn't leave the value parenthesis state until all open parenthesis are matched with a close.
1 parent 56d0145 commit d93592f

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

lib/parse.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ CSSOM.parse = function parse(token) {
2424

2525
var index;
2626
var buffer = "";
27+
var valueParenthesisDepth = 0;
2728

2829
var SIGNIFICANT_WHITESPACE = {
2930
"selector": true,
3031
"value": true,
32+
"value-parenthesis": true,
3133
"atRule": true,
3234
"importRule-begin": true,
3335
"importRule": true,
@@ -263,16 +265,23 @@ CSSOM.parse = function parse(token) {
263265
}
264266
} else {
265267
state = 'value-parenthesis';
268+
//always ensure this is reset to 1 on transition
269+
//from value to value-parenthesis
270+
valueParenthesisDepth = 1;
266271
buffer += character;
267272
}
273+
} else if (state === 'value-parenthesis') {
274+
valueParenthesisDepth++;
275+
buffer += character;
268276
} else {
269277
buffer += character;
270278
}
271279
break;
272280

273281
case ")":
274282
if (state === 'value-parenthesis') {
275-
state = 'value';
283+
valueParenthesisDepth--;
284+
if (valueParenthesisDepth === 0) state = 'value';
276285
}
277286
buffer += character;
278287
break;

spec/parse.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,50 @@ var TESTS = [
445445
return result;
446446
})()
447447
},
448+
{
449+
input: ".calc{width: calc(100% - 15px);}",
450+
result: (function() {
451+
var result = {
452+
cssRules: [
453+
{
454+
selectorText: '.calc',
455+
parentRule: null,
456+
style: {
457+
0: 'width',
458+
width: 'calc(100% - 15px)',
459+
length: 1
460+
}
461+
}
462+
],
463+
parentStyleSheet: null
464+
};
465+
result.cssRules[0].parentStyleSheet = result;
466+
result.cssRules[0].style.parentRule = result.cssRules[0];
467+
return result;
468+
})()
469+
},
470+
{
471+
input: ".gradient{background-image: linear-gradient(transparent 50%, rgba(69, 142, 209, 0.04) 50%);}",
472+
result: (function() {
473+
var result = {
474+
cssRules: [
475+
{
476+
selectorText: '.gradient',
477+
parentRule: null,
478+
style: {
479+
0: 'background-image',
480+
"background-image": 'linear-gradient(transparent 50%, rgba(69, 142, 209, 0.04) 50%)',
481+
length: 1
482+
}
483+
}
484+
],
485+
parentStyleSheet: null
486+
};
487+
result.cssRules[0].parentStyleSheet = result;
488+
result.cssRules[0].style.parentRule = result.cssRules[0];
489+
return result;
490+
})()
491+
},
448492
{
449493
input: "@media handheld, only screen and (max-device-width: 480px) {body{max-width:480px}}",
450494
result: (function() {

0 commit comments

Comments
 (0)