Skip to content

Commit

Permalink
Fix: Parser breaks when an end parenthesis occurs in a quoted string
Browse files Browse the repository at this point in the history
Closes #56
Closes #77
  • Loading branch information
NV committed Nov 26, 2015
1 parent e491792 commit 49eb9c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ CSSOM.parse = function parse(token) {
}
break;

case '(':
case "(":
if (state === 'value') {
// ie css expression mode
if (buffer.trim() === 'expression') {
Expand All @@ -250,17 +250,19 @@ CSSOM.parse = function parse(token) {
i = info.idx;
}
} else {
index = token.indexOf(')', i + 1);
if (index === -1) {
parseError('Unmatched "("');
}
buffer += token.slice(i, index + 1);
i = index;
state = 'value-parenthesis';
buffer += character;
}
} else {
buffer += character;
}
break;

case ")":
if (state === 'value-parenthesis') {
state = 'value';
}
buffer += character;
break;

case "!":
Expand Down
22 changes: 22 additions & 0 deletions spec/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,28 @@ var TESTS = [
return result;
})()
},
{
input: "body{background-image: url(')');}",
result: (function() {
var result = {
cssRules: [
{
selectorText: 'body',
parentRule: null,
style: {
0: 'background-image',
'background-image': "url(')')",
length: 1
}
}
],
parentStyleSheet: null
};
result.cssRules[0].parentStyleSheet = result;
result.cssRules[0].style.parentRule = result.cssRules[0];
return result;
})()
},
{
input: ".gradient{background: -moz-linear-gradient(/*);*/top, #1E5799 0%, #7db9e8 100%)}",
result: (function() {
Expand Down

0 comments on commit 49eb9c7

Please sign in to comment.