diff --git a/lib/package/plugins/_pluginUtil.js b/lib/package/plugins/_pluginUtil.js index d9ee63a8..53b02226 100644 --- a/lib/package/plugins/_pluginUtil.js +++ b/lib/package/plugins/_pluginUtil.js @@ -76,6 +76,9 @@ const validateFunctionArgs = (expr, fnStart, argsStart, end) => { // if (argsString.includes(' ')) { // return {fn, error: 'spaces in argument string'}; // } + if (argsString != "" && argsString.trim() == "") { + return { fn, error: "spaces between parens" }; + } if (argsString == "" && !ZERO_ARG_FUNCTIONS.includes(fn)) { return { fn, error: `empty arg string` }; } diff --git a/test/specs/testTemplateCheck.js b/test/specs/testTemplateCheck.js index 3c239bda..0d9be3dc 100644 --- a/test/specs/testTemplateCheck.js +++ b/test/specs/testTemplateCheck.js @@ -17,62 +17,79 @@ /* jslint esversion:9 */ const assert = require("assert"), - pu = require("../../lib/package/plugins/_pluginUtil.js"); + pu = require("../../lib/package/plugins/_pluginUtil.js"); -describe("TemplateCheck", function() { +describe("TemplateCheck", function () { const testCases = [ - ["{}", "empty function name at position 1"], - ["{a}", undefined], - ["{{a}", 'unexpected character at position 1: {'], - ["{{a}}", 'unexpected character at position 1: {'], - ["{[]}", 'unexpected character at position 1: ['], - ["{a[]}", 'unexpected character at position 2: ['], - ["{a", 'unterminated curly brace'], - ["}a", 'unexpected close curly at position 0'], - ["{a}}", 'unexpected close curly at position 3'], - ["}a{", 'unexpected close curly at position 0'], - ["{a}b", undefined], - ["{a}{b}", undefined], - ["{a}.{b}", undefined], - ["{a.b}", undefined], - ["{3}", 'unexpected character at position 1: 3'], - ["{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp)}", undefined], - ["{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp) }", - 'unexpected character at position 62: '], - [`{ "organization": "{organization.name}", "environment": "{environment.name}" } `, undefined], - [`{ "organization": "{organization.name}", "environment": "{environment.{name}}" } `, - 'unexpected character at position 71: {'], - [`{ "organization": "{organization.name}", "other": {"environment": "{environment.name}" } } `, - undefined], - ["{createUuid()}", undefined], - ["{createUuid( )}", 'spaces in argument string for function createUuid'], - ["{timeFormatUTCMs()}", 'empty arg string for function timeFormatUTCMs'], - ["{notARealfunction()}", 'unsupported function name (notARealfunction)'], - ["{createUuid[]}", 'unexpected character at position 11: ['], - ["{ createUuid() }", undefined], // but ineffective - ]; + ["{}", "empty function name at position 1"], + ["{a}", undefined], + ["{{a}", "unexpected character at position 1: {"], + ["{{a}}", "unexpected character at position 1: {"], + ["{[]}", "unexpected character at position 1: ["], + ["{a[]}", "unexpected character at position 2: ["], + ["{a", "unterminated curly brace"], + ["}a", "unexpected close curly at position 0"], + ["{a}}", "unexpected close curly at position 3"], + ["}a{", "unexpected close curly at position 0"], + ["{a}b", undefined], + ["{a}{b}", undefined], + ["{a}.{b}", undefined], + ["{a.b}", undefined], + ["{3}", "unexpected character at position 1: 3"], + [ + "{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp)}", + undefined, + ], + [ + "{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp) }", + "unexpected character at position 62: ", + ], + [ + `{ "organization": "{organization.name}", "environment": "{environment.name}" } `, + undefined, + ], + [ + `{ "organization": "{organization.name}", "environment": "{environment.{name}}" } `, + "unexpected character at position 71: {", + ], + [ + `{ "organization": "{organization.name}", "other": {"environment": "{environment.name}" } } `, + undefined, + ], + ["{createUuid()}", undefined], + ["{createUuid( )}", "spaces between parens for function createUuid"], + ["{timeFormatUTCMs()}", "empty arg string for function timeFormatUTCMs"], + ["{notARealfunction()}", "unsupported function name (notARealfunction)"], + ["{createUuid[]}", "unexpected character at position 11: ["], + ["{ createUuid() }", undefined], // but ineffective + ]; - testCases.forEach( (item, _ix) => { + testCases.forEach((item, _ix) => { const [expression, expectedError] = item; - it(`validateTemplate (${expression}) should return ${expectedError}`, function() { + it(`validateTemplate (${expression}) should return ${expectedError}`, function () { const actualResult = pu.validateTemplate(expression); assert.equal(actualResult, expectedError); }); }); }); -describe("PropertySetRefCheck", function() { +describe("PropertySetRefCheck", function () { const testCases = [ - ["{foo.bar}", undefined], - ["{foo.bar}.{var2}.setting", 'there is more than one dot in the template result'], - ["foo.bar.var2.setting", 'there are 3 dots ( !=1 ) in the template result'], - ["{foo.bar}.setting", undefined], - ["{foo.bar}.{flow.var2}", undefined], - ]; + ["{foo.bar}", undefined], + [ + "{foo.bar}.{var2}.setting", + "there is more than one dot in the template result", + ], + ["foo.bar.var2.setting", "there are 3 dots ( !=1 ) in the template result"], + ["{foo.bar}.setting", undefined], + ["{foo.bar}.{flow.var2}", undefined], + ]; - testCases.forEach( (item, _ix) => { + testCases.forEach((item, _ix) => { const [expression, expectedResult] = item; - it(`PropertySetRef (${expression}) should be ${expectedResult?'valid':'not valid'}`, function() { + it(`PropertySetRef (${expression}) should be ${ + expectedResult ? "valid" : "not valid" + }`, function () { const actualResult = pu.validatePropertySetRef(expression); assert.equal(actualResult, expectedResult); });