Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 85a824e

Browse files
committed
Fix empty selector
1 parent ccc7e31 commit 85a824e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

css-explain.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
// Returns 'id', 'class', 'tag', or 'universal'.
7676
function detectCategory(parts) {
7777
var last = parts[parts.length-1];
78-
if (last.match(match.ID)) {
78+
if (!last) {
79+
return 'universal';
80+
} else if (last.match(match.ID)) {
7981
return 'id';
8082
} else if (last.match(match.CLASS)) {
8183
return 'class';
@@ -99,8 +101,11 @@
99101
var score = 1;
100102
var messages = [];
101103

104+
if (!last) {
105+
}
106+
102107
// ID category
103-
if (last.match(match.ID)) {
108+
else if (last.match(match.ID)) {
104109
// Check for redundant class name
105110
if (last.match(match.CLASS)) {
106111
messages.push("ID is overly qualified by a class name");

test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ exports.category = {
146146
};
147147

148148
exports.specificity = function(test) {
149+
test.deepEqual(cssExplain("").specificity, [0, 0, 0]);
150+
149151
test.deepEqual(cssExplain("*").specificity, [0, 0, 0]);
150152
test.deepEqual(cssExplain("li").specificity, [0, 0, 1]);
151153
test.deepEqual(cssExplain("li:first-line").specificity, [0, 0, 2]);

0 commit comments

Comments
 (0)