Skip to content

Commit

Permalink
fix regression in previous commit which broke parsing for json string…
Browse files Browse the repository at this point in the history
…s inside :val() and :contains()
  • Loading branch information
lloyd committed Jun 2, 2011
1 parent e3ce679 commit 24d5433
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion JSONSelect.md
Expand Up @@ -206,7 +206,7 @@ See [https://github.com/lloyd/JSONSelectTests](https://github.com/lloyd/JSONSele
In no particular order.

* [http://json.org/](http://json.org/)
* [http://www.w3.org/TR/css3-selectors/]( * http://www.w3.org/TR/css3-selectors/)
* [http://www.w3.org/TR/css3-selectors/](http://www.w3.org/TR/css3-selectors/)
* [http://ejohn.org/blog/selectors-that-people-actually-use/](http://ejohn.org/blog/selectors-that-people-actually-use/)
* [http://shauninman.com/archive/2008/05/05/css\_qualified\_selectors]( * http://shauninman.com/archive/2008/05/05/css_qualified_selectors)
* [http://snook.ca/archives/html\_and\_css/css-parent-selectors](http://snook.ca/archives/html_and_css/css-parent-selectors)
Expand Down
17 changes: 9 additions & 8 deletions src/jsonselect.js
Expand Up @@ -49,7 +49,8 @@
psc: 1, // pseudo class
psf: 2, // pseudo class function
typ: 3, // type
str: 4 // string
str: 4, // string
ide: 5 // identifiers (or "classes", stuff after a dot)
};

// The primary lexing regular expression in jsonselect
Expand All @@ -67,12 +68,12 @@
"(:(?:nth-child|nth-last-child|has|expr|val|contains))|" +
// (6) bogusly named pseudo something or others
"(:\\w+)|" +
// (7) JSON strings
"\\.(\\\"(?:[^\\\\]|\\\\[^\\\"])*\\\")|" +
// (7 & 8) identifiers and JSON strings
"(?:(\\.)?(\\\"(?:[^\\\\]|\\\\[^\\\"])*\\\"))|" +
// (8) bogus JSON strings missing a trailing quote
"(\\\")|" +
// (9) identifiers (unquoted)
"\\.((?:[_a-zA-Z]|[^\\0-\\0177]|\\\\[^\\r\\n\\f0-9a-fA-F])(?:[_a-zA-Z0-9\\-]|[^\\u0000-\\u0177]|(?:\\\\[^\\r\\n\\f0-9a-fA-F]))*)" +
"\\.((?:[_a-zA-Z]|[^\\0-\\0177]|\\\\[^\\r\\n\\f0-9a-fA-F])(?:[_a-zA-Z0-9\\-]|[^\\u0000-\\u0177]|(?:\\\\[^\\r\\n\\f0-9a-fA-F]))*)" +
")"
);

Expand All @@ -90,9 +91,9 @@
else if (m[4]) a = [off, toks.psc, m[0]];
else if (m[5]) a = [off, toks.psf, m[0]];
else if (m[6]) te("upc");
else if (m[7]) a = [off, toks.str, jsonParse(m[7])];
else if (m[8]) te("ujs");
else if (m[9]) a = [off, toks.str, m[9].replace(/\\([^\r\n\f0-9a-fA-F])/g,"$1")];
else if (m[8]) a = [off, m[7] ? toks.ide : toks.str, jsonParse(m[8])];
else if (m[9]) te("ujs");
else if (m[10]) a = [off, toks.ide, m[10].replace(/\\([^\r\n\f0-9a-fA-F])/g,"$1")];
return a;
}

Expand Down Expand Up @@ -320,7 +321,7 @@
while (true) {
if (l === undefined) {
break;
} else if (l[1] === toks.str) {
} else if (l[1] === toks.ide) {
if (s.id) te("nmi");
s.id = l[2];
} else if (l[1] === toks.psc) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests

0 comments on commit 24d5433

Please sign in to comment.