diff --git a/independent-projects/qute/core/src/main/java/io/quarkus/qute/Parser.java b/independent-projects/qute/core/src/main/java/io/quarkus/qute/Parser.java index d1f36a32be154e..cd93760c4142ed 100644 --- a/independent-projects/qute/core/src/main/java/io/quarkus/qute/Parser.java +++ b/independent-projects/qute/core/src/main/java/io/quarkus/qute/Parser.java @@ -1064,9 +1064,11 @@ private static Part createPart(Supplier idGenerator, String namespace, value = literal.toString(); } else { throw TemplateException.builder() - .message((literal == null ? "Null" : "Non-literal") - + " value used in bracket notation [{value}] {origin}") + .message((literal == null ? "Null value" : "Non-literal value [{value}]") + + " used in bracket notation in expression \\{{expr}\\}{#if origin.hasNonGeneratedTemplateId??} in{origin}{/if}") .argument("value", value) + .argument("expr", exprValue) + .origin(origin) .build(); } } else { diff --git a/independent-projects/qute/core/src/test/java/io/quarkus/qute/ParserTest.java b/independent-projects/qute/core/src/test/java/io/quarkus/qute/ParserTest.java index 06cebe0e764b27..deb8c6dfdeeff0 100644 --- a/independent-projects/qute/core/src/test/java/io/quarkus/qute/ParserTest.java +++ b/independent-projects/qute/core/src/test/java/io/quarkus/qute/ParserTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -468,6 +469,15 @@ public void testSectionParameterWithNestedSingleQuotationMark() { } + @Test + public void testNonLiteralBracketNotation() { + TemplateException e = assertThrows(TemplateException.class, + () -> Engine.builder().addDefaults().build().parse("{foo[bar]}", null, "baz")); + assertNotNull(e.getOrigin()); + assertEquals("Non-literal value [bar] used in bracket notation in expression {foo[bar]} in template [baz] line 1", + e.getMessage()); + } + private void assertSectionParams(Engine engine, String content, Map expectedParams) { Template template = engine.parse(content); SectionNode node = template.findNodes(n -> n.isSection() && n.asSection().name.equals("let")).iterator().next()