diff --git a/taglibs/core/util/parseFor.js b/taglibs/core/util/parseFor.js index a03fdf6f5..6519fe3a5 100644 --- a/taglibs/core/util/parseFor.js +++ b/taglibs/core/util/parseFor.js @@ -82,6 +82,14 @@ function parseExpression(str, errorMessage) { } } +function parseStatement(str, errorMessage) { + try { + return compiler.builder.parseStatement(str); + } catch(e) { + throwError(errorMessage + ': ' + e.message); + } +} + function createNumberExpression(str, errorMessage) { if (str == null) { return null; @@ -294,6 +302,18 @@ module.exports = function(str) { statusVarName = buildIdentifier(statusVarName, 'Invalid status-var option'); } + if (forInit) { + forInit = parseStatement(forInit, 'Invalid for loop init'); + } + + if (forTest) { + forTest = parseExpression(forTest, 'Invalid for loop test'); + } + + if (forUpdate) { + forUpdate = parseExpression(forUpdate, 'Invalid for loop update'); + } + // No more tokens... now we need to sort out what happened if (loopType === 'ForEach') { return { diff --git a/test/fixtures/parseFor/autotest/nativeFor-empty-init/expected.json b/test/fixtures/parseFor/autotest/nativeFor-empty-init/expected.json index 18e85ce7b..e6ff129f9 100644 --- a/test/fixtures/parseFor/autotest/nativeFor-empty-init/expected.json +++ b/test/fixtures/parseFor/autotest/nativeFor-empty-init/expected.json @@ -1,6 +1,33 @@ { "loopType": "For", "init": "", - "test": " i