diff --git a/garden-service/src/template-string-parser.pegjs b/garden-service/src/template-string-parser.pegjs index d3f507c0a9..91d9982071 100644 --- a/garden-service/src/template-string-parser.pegjs +++ b/garden-service/src/template-string-parser.pegjs @@ -48,10 +48,10 @@ InvalidFormatString } FormatStart - = ws "${" ws + = "${" ws FormatEnd - = ws "}" ws + = ws "}" Identifier = [a-zA-Z][a-zA-Z0-9_\-]* { return text() } diff --git a/garden-service/test/unit/src/template-string.ts b/garden-service/test/unit/src/template-string.ts index 58ef9d407a..16f31dae24 100644 --- a/garden-service/test/unit/src/template-string.ts +++ b/garden-service/test/unit/src/template-string.ts @@ -38,6 +38,21 @@ describe("resolveTemplateString", async () => { expect(res).to.equal("value-suffix") }) + it("should interpolate a format string with a prefix with whitespace", async () => { + const res = await resolveTemplateString("prefix ${some}", new TestContext({ some: "value" })) + expect(res).to.equal("prefix value") + }) + + it("should interpolate a format string with a suffix with whitespace", async () => { + const res = await resolveTemplateString("${some} suffix", new TestContext({ some: "value" })) + expect(res).to.equal("value suffix") + }) + + it("should correctly interpolate a format string with surrounding whitespace", async () => { + const res = await resolveTemplateString("prefix ${some} suffix", new TestContext({ some: "value" })) + expect(res).to.equal("prefix value suffix") + }) + it("should handle a nested key", async () => { const res = await resolveTemplateString("${some.nested}", new TestContext({ some: { nested: "value" } })) expect(res).to.equal("value")