Skip to content

Commit 24d5433

Browse files
committed
fix regression in previous commit which broke parsing for json strings inside :val() and :contains()
1 parent e3ce679 commit 24d5433

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

JSONSelect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ See [https://github.com/lloyd/JSONSelectTests](https://github.com/lloyd/JSONSele
206206
In no particular order.
207207

208208
* [http://json.org/](http://json.org/)
209-
* [http://www.w3.org/TR/css3-selectors/]( * http://www.w3.org/TR/css3-selectors/)
209+
* [http://www.w3.org/TR/css3-selectors/](http://www.w3.org/TR/css3-selectors/)
210210
* [http://ejohn.org/blog/selectors-that-people-actually-use/](http://ejohn.org/blog/selectors-that-people-actually-use/)
211211
* [http://shauninman.com/archive/2008/05/05/css\_qualified\_selectors]( * http://shauninman.com/archive/2008/05/05/css_qualified_selectors)
212212
* [http://snook.ca/archives/html\_and\_css/css-parent-selectors](http://snook.ca/archives/html_and_css/css-parent-selectors)

src/jsonselect.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
psc: 1, // pseudo class
5050
psf: 2, // pseudo class function
5151
typ: 3, // type
52-
str: 4 // string
52+
str: 4, // string
53+
ide: 5 // identifiers (or "classes", stuff after a dot)
5354
};
5455

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

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

@@ -320,7 +321,7 @@
320321
while (true) {
321322
if (l === undefined) {
322323
break;
323-
} else if (l[1] === toks.str) {
324+
} else if (l[1] === toks.ide) {
324325
if (s.id) te("nmi");
325326
s.id = l[2];
326327
} else if (l[1] === toks.psc) {

0 commit comments

Comments
 (0)