From dcccb617813625c224a28242c5b965bb4cd6f189 Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Mon, 30 Aug 2021 18:57:05 +0100 Subject: [PATCH] Tighten parameter substitution tolerance In collection templating syntax, do not tolerate whitespace after dollar sign. So while `{{ $param }}` is valid `{{ $ param }}` will be ignored. --- .../Expressions/SyntaxParsers/ParameterSubstitutionParser.ts | 2 +- .../SyntaxParsers/ParameterSubstitutionParser.spec.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.ts b/src/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.ts index 19e0951d..79945830 100644 --- a/src/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.ts +++ b/src/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.ts @@ -1,7 +1,7 @@ import { RegexParser, IPrimitiveExpression } from '../Parser/RegexParser'; export class ParameterSubstitutionParser extends RegexParser { - protected readonly regex = /{{\s*\$\s*([^}| ]+)\s*}}/g; + protected readonly regex = /{{\s*\$([^}| ]+)\s*}}/g; protected buildExpression(match: RegExpMatchArray): IPrimitiveExpression { const parameterName = match[1]; return { diff --git a/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts b/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts index b3b46eaa..70863cf1 100644 --- a/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts +++ b/tests/unit/application/Parser/Script/Compiler/Expressions/SyntaxParsers/ParameterSubstitutionParser.spec.ts @@ -23,6 +23,11 @@ describe('ParameterSubstitutionParser', () => { code: 'He{{$firstParameter}}!!', expected: [new ExpressionPosition(2, 21) ], }, + { + name: 'does not tolerate space after dollar sign', + code: 'He{{ $ firstParameter }}!!', + expected: [ ], + }, ]; for (const testCase of testCases) { it(testCase.name, () => {