diff --git a/index.js b/index.js index b82beb7..88dd62a 100644 --- a/index.js +++ b/index.js @@ -157,9 +157,13 @@ module.exports = function(css, options){ if ('/' != css.charAt(0) || '*' != css.charAt(1)) return; var i = 2; - while (null != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i; + while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i; i += 2; + if ("" === css.charAt(i-1)) { + return error('End of comment missing'); + } + var str = css.slice(2, i - 2); column += 2; updatePosition(str); diff --git a/test/css-parse.js b/test/css-parse.js index 58598bd..1e22712 100644 --- a/test/css-parse.js +++ b/test/css-parse.js @@ -45,4 +45,19 @@ describe('parse(str)', function(){ parse('b { color: red; }\n{ color: green; }\na {color: blue; }'); }); }) + + it('should throw when a broken comment is found', function () { + assert.throws(function(){ + parse('thing { color: red; } /* b { color: blue; }'); + }); + + assert.throws(function(){ + parse('/*'); + }); + + /* Nested comments should be fine */ + assert.doesNotThrow(function(){ + parse('/* /* */'); + }); + }) })