From f2d7c7d98b10565eb192559cd2a75af2ee6a29e8 Mon Sep 17 00:00:00 2001 From: Frank van Gemeren Date: Sun, 28 May 2017 02:51:41 +0200 Subject: [PATCH] Fixes #229. Throws syntax error for empty functions and doesnt block anymore. --- src/css/Parser.js | 7 ++++++- src/css/TokenStream.js | 2 +- tests/css/Parser.js | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/css/Parser.js b/src/css/Parser.js index 65525378..d4290c74 100644 --- a/src/css/Parser.js +++ b/src/css/Parser.js @@ -1986,6 +1986,11 @@ Parser.prototype = function() { functionText = tokenStream.token().value; this._readWhitespace(); expr = this._expr(true); + if (expr === null) { + // the FUNCTION is set if there's a ( . It doesn't check for a closing ) in identOrFunctionToken in TokenStream.. + // if there's nothing between the brackets, expr is null + throw new SyntaxError("Expected an expression in the function on line " + tokenStream.token().startLine + ", col " + tokenStream.token().startCol + ".", tokenStream.token().startLine, tokenStream.token().startCol); + } functionText += expr; // START: Horrible hack in case it's an IE filter @@ -2009,7 +2014,7 @@ Parser.prototype = function() { //functionText += this._term(); lt = tokenStream.peek(); - while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN) { + while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN && lt !== Tokens.EOF) { tokenStream.get(); functionText += tokenStream.token().value; lt = tokenStream.peek(); diff --git a/src/css/TokenStream.js b/src/css/TokenStream.js index 70acd7a7..11e8b670 100755 --- a/src/css/TokenStream.js +++ b/src/css/TokenStream.js @@ -541,7 +541,7 @@ TokenStream.prototype = mix(new TokenStreamBase(), { } } else if (reader.peek() === ":") { // might be an IE function - // IE-specific functions always being with progid: + // IE-specific functions always begin with progid: if (ident.toLowerCase() === "progid") { ident += reader.readTo("("); tt = Tokens.IE_FUNCTION; diff --git a/tests/css/Parser.js b/tests/css/Parser.js index f050f412..f13edd1e 100644 --- a/tests/css/Parser.js +++ b/tests/css/Parser.js @@ -1415,7 +1415,8 @@ var YUITest = require("yuitest"), _should: { error: { - testIEFilter5: "Unexpected token '=' at line 1, col 14." + testIEFilter5: "Unexpected token '=' at line 1, col 14.", + testFunctionBroken: "Expected an expression in the function on line 1, col 1." } }, @@ -1505,6 +1506,11 @@ var YUITest = require("yuitest"), var result = parser.parsePropertyValue("alpha(opacity=10)"); Assert.isInstanceOf(parserlib.css.PropertyValue, result); + }, + + testFunctionBroken: function() { + var parser = new Parser(); + parser.parsePropertyValue("calc("); }