Skip to content

Commit f2d7c7d

Browse files
author
Frank van Gemeren
committed
Fixes #229. Throws syntax error for empty functions and doesnt block anymore.
1 parent f306a55 commit f2d7c7d

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/css/Parser.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,11 @@ Parser.prototype = function() {
19861986
functionText = tokenStream.token().value;
19871987
this._readWhitespace();
19881988
expr = this._expr(true);
1989+
if (expr === null) {
1990+
// the FUNCTION is set if there's a ( . It doesn't check for a closing ) in identOrFunctionToken in TokenStream..
1991+
// if there's nothing between the brackets, expr is null
1992+
throw new SyntaxError("Expected an expression in the function on line " + tokenStream.token().startLine + ", col " + tokenStream.token().startCol + ".", tokenStream.token().startLine, tokenStream.token().startCol);
1993+
}
19891994
functionText += expr;
19901995

19911996
// START: Horrible hack in case it's an IE filter
@@ -2009,7 +2014,7 @@ Parser.prototype = function() {
20092014

20102015
//functionText += this._term();
20112016
lt = tokenStream.peek();
2012-
while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN) {
2017+
while (lt !== Tokens.COMMA && lt !== Tokens.S && lt !== Tokens.RPAREN && lt !== Tokens.EOF) {
20132018
tokenStream.get();
20142019
functionText += tokenStream.token().value;
20152020
lt = tokenStream.peek();

src/css/TokenStream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
541541
}
542542
} else if (reader.peek() === ":") { // might be an IE function
543543

544-
// IE-specific functions always being with progid:
544+
// IE-specific functions always begin with progid:
545545
if (ident.toLowerCase() === "progid") {
546546
ident += reader.readTo("(");
547547
tt = Tokens.IE_FUNCTION;

tests/css/Parser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,8 @@ var YUITest = require("yuitest"),
14151415

14161416
_should: {
14171417
error: {
1418-
testIEFilter5: "Unexpected token '=' at line 1, col 14."
1418+
testIEFilter5: "Unexpected token '=' at line 1, col 14.",
1419+
testFunctionBroken: "Expected an expression in the function on line 1, col 1."
14191420
}
14201421
},
14211422

@@ -1505,6 +1506,11 @@ var YUITest = require("yuitest"),
15051506
var result = parser.parsePropertyValue("alpha(opacity=10)");
15061507

15071508
Assert.isInstanceOf(parserlib.css.PropertyValue, result);
1509+
},
1510+
1511+
testFunctionBroken: function() {
1512+
var parser = new Parser();
1513+
parser.parsePropertyValue("calc(");
15081514
}
15091515

15101516

0 commit comments

Comments
 (0)