Skip to content

Commit e3bfc4b

Browse files
committed
Merge pull request #73 from jonathanKingston/master
Fixes CSS parsing error, throws an end of comment issue. fixes #69
2 parents 1d51861 + 482cc96 commit e3bfc4b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ module.exports = function(css, options){
157157
if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
158158

159159
var i = 2;
160-
while (null != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
160+
while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
161161
i += 2;
162162

163+
if ("" === css.charAt(i-1)) {
164+
return error('End of comment missing');
165+
}
166+
163167
var str = css.slice(2, i - 2);
164168
column += 2;
165169
updatePosition(str);

test/css-parse.js

+15
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ describe('parse(str)', function(){
4545
parse('b { color: red; }\n{ color: green; }\na {color: blue; }');
4646
});
4747
})
48+
49+
it('should throw when a broken comment is found', function () {
50+
assert.throws(function(){
51+
parse('thing { color: red; } /* b { color: blue; }');
52+
});
53+
54+
assert.throws(function(){
55+
parse('/*');
56+
});
57+
58+
/* Nested comments should be fine */
59+
assert.doesNotThrow(function(){
60+
parse('/* /* */');
61+
});
62+
})
4863
})

0 commit comments

Comments
 (0)