From efd9a742f9e5fce8aa8c5c8ead82bb8efaa31b9c Mon Sep 17 00:00:00 2001 From: Libo Song Date: Tue, 12 Dec 2023 11:12:39 -0500 Subject: [PATCH] Fix bad tag token. --- src/main/java/com/hubspot/jinjava/tree/parse/TagToken.java | 7 +++++++ .../java/com/hubspot/jinjava/tree/parse/TagTokenTest.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/hubspot/jinjava/tree/parse/TagToken.java b/src/main/java/com/hubspot/jinjava/tree/parse/TagToken.java index d73c33b22..14a11ff49 100644 --- a/src/main/java/com/hubspot/jinjava/tree/parse/TagToken.java +++ b/src/main/java/com/hubspot/jinjava/tree/parse/TagToken.java @@ -44,6 +44,13 @@ public int getType() { @Override protected void parse() { if (image.length() < 4) { + if (image.equals("{%}")) { + tagName = ""; + rawTagName = ""; + helpers = ""; + content = ""; + return; + } throw new TemplateSyntaxException( image, "Malformed tag token", diff --git a/src/test/java/com/hubspot/jinjava/tree/parse/TagTokenTest.java b/src/test/java/com/hubspot/jinjava/tree/parse/TagTokenTest.java index 83bd6b96d..5bc0b8962 100644 --- a/src/test/java/com/hubspot/jinjava/tree/parse/TagTokenTest.java +++ b/src/test/java/com/hubspot/jinjava/tree/parse/TagTokenTest.java @@ -38,4 +38,11 @@ public void itThrowsParseErrorWhenMalformed() { assertThat(e).hasMessageContaining("Malformed"); } } + + @Test + public void testParseEmptyTagWithHelpers() { + TagToken t = new TagToken("{%}", 1, 2, SYMBOLS); + assertThat(t.getTagName()).isEqualTo(""); + assertThat(t.getHelpers().trim()).isEqualTo(""); + } }