Skip to content

Commit

Permalink
Correctly handle quotes in values. Closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstimmerman committed Nov 19, 2013
1 parent 76681ea commit db690c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ function lex(css) {
case "'":
switch (getState()) {
case 'double-string':
if ('"' === ch) {
if ('"' === ch && '\\' !== peek(-1)) {
popState();
}
break;

case 'single-string':
if ("'" === ch) {
if ("'" === ch && '\\' !== peek(-1)) {
popState();
}
break;
Expand All @@ -457,7 +457,9 @@ function lex(css) {
break;

default:
pushState('"' === ch ? 'double-string' : 'single-string');
if ('\\' !== peek(-1)) {
pushState('"' === ch ? 'double-string' : 'single-string');
}
}

buffer += ch;
Expand Down
21 changes: 21 additions & 0 deletions test/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ describe('Syntax', function () {
});
});

describe('strings in values', function () {
it('should work', function () {
var css = [
'.sele {',
'content: "hel\\"lo";',
'}'
].join('\n');

ensure(css);

css = [
'.sele {',
'voice-family: "\\"}\\"";',
'voice-family: inherit;',
'}'
].join('\n');

ensure(css);
});
});

describe('unexpected braces and semi-colons', function () {
it('should be ignored', function () {
var css = [
Expand Down

0 comments on commit db690c5

Please sign in to comment.