Skip to content

Commit 31cd09a

Browse files
committed
fixed invalid number parsing
1 parent 16563d1 commit 31cd09a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/parse.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function elementMatch(match, namespace, name) {
9494
type: "element",
9595
name: unescape(name)
9696
};
97+
9798
if(namespace) {
9899
newToken.namespace = unescape(namespace.substr(0, namespace.length - 1));
99100
}
@@ -175,7 +176,7 @@ var parser = new Parser({
175176
"(\\*\\|)((?:\\\\.|[A-Za-z_\\-0-9])+)": elementMatch,
176177
"(\\*\\|)\\*": universalMatch,
177178
"((?:\\\\.|[A-Za-z_\\-0-9])*\\|)?\\*": universalMatch,
178-
"((?:\\\\.|[A-Za-z_\\-0-9])*\\|)?((?:\\\\.|[A-Za-z_\\-0-9])+)": elementMatch,
179+
"((?:\\\\.|[A-Za-z_\\-0-9])*\\|)?((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": elementMatch,
179180
"\\[([^\\]]+)\\]": attributeMatch,
180181
"(\\s*)\\)": nestedEnd,
181182
"(\\s*)([>+~])(\\s*)": operatorMatch,

test/test-cases.js

+18
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,23 @@ module.exports = {
372372
{ type: "spacing", value: " " },
373373
{ type: "element", name: "b" }
374374
])
375+
],
376+
377+
"invalid number": [
378+
"0%",
379+
singleSelector([
380+
{ type: "invalid", value: "0" },
381+
{ type: "invalid", value: "%" }
382+
])
383+
],
384+
385+
"invalid class name": [
386+
".10a0",
387+
singleSelector([
388+
{ type: "invalid", value: "." },
389+
{ type: "invalid", value: "1" },
390+
{ type: "invalid", value: "0" },
391+
{ type: "element", name: "a0" }
392+
])
375393
]
376394
};

0 commit comments

Comments
 (0)