Skip to content

Commit

Permalink
Allow \' and \" in strings. #39
Browse files Browse the repository at this point in the history
  • Loading branch information
NV committed Jul 18, 2012
1 parent 6911c38 commit 30c066c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ CSSOM.parse = function parse(token) {

// String
case '"':
index = token.indexOf('"', i + 1) + 1;
if (!index) {
parseError('Unmatched "');
}
index = i + 1;
do {
index = token.indexOf('"', index) + 1;
if (!index) {
parseError('Unmatched "');
}
} while (token[index - 2] === '\\')
buffer += token.slice(i, index);
i = index - 1;
switch (state) {
Expand All @@ -90,10 +93,13 @@ CSSOM.parse = function parse(token) {
break;

case "'":
index = token.indexOf("'", i + 1) + 1;
if (!index) {
parseError("Unmatched '");
}
index = i + 1;
do {
index = token.indexOf("'", index) + 1;
if (!index) {
parseError("Unmatched '");
}
} while (token[index - 2] === '\\')
buffer += token.slice(i, index);
i = index - 1;
switch (state) {
Expand Down
21 changes: 21 additions & 0 deletions spec/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,30 @@ describe('parse', function() {
});
});

given('a{content:"\\""}', function(input) {
var parsed = CSSOM.parse(input);
expect(parsed.cssRules[0].style.content).toBe('"\\""');
});

given("a{content:'\\''}", function(input) {
var parsed = CSSOM.parse(input);
expect(parsed.cssRules[0].style.content).toBe("'\\''");
});

given('a{content:"abc\\"\\"d\\"ef"}', function(input) {
var parsed = CSSOM.parse(input);
expect(parsed.cssRules[0].style.content).toBe('"abc\\"\\"d\\"ef"');
});

given("a{content:'abc\\'\\'d\\'ef'}", function(input) {
var parsed = CSSOM.parse(input);
expect(parsed.cssRules[0].style.content).toBe("'abc\\'\\'d\\'ef'");
});

});
});


/**
* Recursively remove all keys which start with '_', except "_vendorPrefix", which needs to be tested against.
* @param {Object} object
Expand Down

0 comments on commit 30c066c

Please sign in to comment.