Skip to content

Commit 6b63062

Browse files
authored
Merge pull request #49629 from mkouba/qute-include-params-fix
Qute: fix params processing for include section
2 parents 71c2032 + 6ed50c7 commit 6b63062

File tree

15 files changed

+58
-31
lines changed

15 files changed

+58
-31
lines changed

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/PropertyNotFoundDevModeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public class PropertyNotFoundDevModeTest {
2727
@Test
2828
public void testExceptionIsThrown() {
2929
assertEquals(
30-
"Rendering error in template [foo.html] line 1: Key \"foo\" not found in the template data map with keys [] in expression {foo.surname}",
30+
"Rendering error in template [foo.html:1]: Key \"foo\" not found in the template data map with keys [] in expression {foo.surname}",
3131
RestAssured.get("test-foo").then().statusCode(200).extract().body().asString());
3232
assertEquals(
33-
"Rendering error in template [bar.html] line 1: Property \"name\" not found on the base object \"java.lang.String\" in expression {bar.name}",
33+
"Rendering error in template [bar.html:1]: Property \"name\" not found on the base object \"java.lang.String\" in expression {bar.name}",
3434
RestAssured.get("test-bar").then().statusCode(200).extract().body().asString());
3535
}
3636

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/enums/TemplateEnumIgnoredTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testTemplateData() {
3131
assertThatExceptionOfType(TemplateException.class)
3232
.isThrownBy(() -> engine.parse("{TransactionType:FOO}", null, "bar").render())
3333
.withMessage(
34-
"Rendering error in template [bar] line 1: No namespace resolver found for [TransactionType] in expression {TransactionType:FOO}");
34+
"Rendering error in template [bar:1]: No namespace resolver found for [TransactionType] in expression {TransactionType:FOO}");
3535

3636
}
3737

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/enums/TemplateEnumInvalidTargetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testTemplateEnum() {
2727
assertThatExceptionOfType(TemplateException.class)
2828
.isThrownBy(() -> engine.parse("{Transactions:VAL}", null, "bar").render())
2929
.withMessage(
30-
"Rendering error in template [bar] line 1: No namespace resolver found for [Transactions] in expression {Transactions:VAL}");
30+
"Rendering error in template [bar:1]: No namespace resolver found for [Transactions] in expression {Transactions:VAL}");
3131

3232
}
3333

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/include/InsertTagConflictTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class InsertTagConflictTest {
3131
}
3232
assertNotNull(te);
3333
assertTrue(te.getMessage().contains(
34-
"Parser error in template [base.html] line 1: {#insert} defined in the {#include} conflicts with an existing section/tag: row"),
34+
"Parser error in template [base.html:1]: {#insert} defined in the {#include} conflicts with an existing section/tag: row"),
3535
te.getMessage());
3636
});;
3737

extensions/qute/deployment/src/test/java/io/quarkus/qute/deployment/tag/UserTagArgumentsValidationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class UserTagArgumentsValidationTest {
2727
}
2828
assertThat(root)
2929
.isInstanceOf(TemplateException.class)
30-
.hasMessageContaining("Found incorrect expressions (1)").hasMessageContaining("{_args.sizes}");
30+
.hasMessageContaining("Found incorrect expressions (1)")
31+
.hasMessageContaining("{_args.sizes}");
3132
});
3233

3334
@Test

independent-projects/qute/core/src/main/java/io/quarkus/qute/IncludeSectionHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ protected String getTemplateId(SectionInitContext context) {
154154
}
155155
String templateParam = context.getParameter(TEMPLATE);
156156
if (templateParam == null) {
157-
throw context.error("Neither the template id nor the template name was specified").build();
157+
throw context.error("Neither the template id nor the template name parameter was specified")
158+
.build();
158159
}
159160
if (LiteralSupport.isStringLiteralSeparator(templateParam.charAt(0))) {
160161
templateParam = templateParam.substring(1, templateParam.length() - 1);
@@ -207,7 +208,10 @@ void addDefaultParams(ParametersInfo.Builder builder) {
207208
}
208209

209210
protected boolean skipBuiltInParam(String value) {
210-
return value != null && !value.startsWith("_");
211+
return value != null
212+
&& !ISOLATED.equals(value)
213+
&& !UNISOLATED.equals(value)
214+
&& !IGNORE_FRAGMENTS.equals(value);
211215
}
212216

213217
@Override

independent-projects/qute/core/src/main/java/io/quarkus/qute/SectionInitContextImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Supplier<Template> getCurrentTemplate() {
7070

7171
@Override
7272
public TemplateException.Builder error(String message) {
73-
return errorInitializer.error(message);
73+
return errorInitializer.error(message).origin(getOrigin());
7474
}
7575

7676
}

independent-projects/qute/core/src/main/java/io/quarkus/qute/TemplateException.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public Optional<String> getCodeName() {
7878
}
7979

8080
private static String toMessage(String messageTemplate, Map<String, Object> arguments, Origin origin) {
81-
if ((arguments == null || arguments.isEmpty()) && origin == null) {
81+
if (messageTemplate == null || messageTemplate.isBlank()) {
82+
return null;
83+
}
84+
if ((arguments == null || arguments.isEmpty())
85+
&& origin == null) {
8286
return messageTemplate;
8387
}
8488
try {
@@ -119,7 +123,7 @@ public Builder cause(Throwable cause) {
119123

120124
/**
121125
* If set then the origin key can be used in the message template. For example <code>Some error {origin}</code> will be
122-
* rendered as <code>Somer error template [foo.html] line 1</code>.
126+
* rendered as <code>Somer error template [foo.html:1]</code>.
123127
*
124128
* @param origin
125129
* @return self

independent-projects/qute/core/src/main/java/io/quarkus/qute/TemplateNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ default boolean hasNonGeneratedTemplateId() {
171171
default void appendTo(StringBuilder builder) {
172172
// It only makes sense to append the info for a template with an explicit id
173173
if (hasNonGeneratedTemplateId()) {
174-
builder.append(" template [").append(getTemplateId()).append("] ").append("line ").append(getLine());
174+
builder.append(" template [").append(getTemplateId()).append(":").append(getLine()).append("]");
175175
}
176176
}
177177

independent-projects/qute/core/src/test/java/io/quarkus/qute/FragmentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testNonUniqueIds() {
5353
TemplateException expected = assertThrows(TemplateException.class,
5454
() -> engine.parse("{#fragment id=another}{foo}{/}{#fragment another}{foo}{/}", null, "bum.html"));
5555
assertEquals(FragmentSectionHelper.Code.NON_UNIQUE_FRAGMENT_ID, expected.getCode());
56-
assertEquals("Parser error in template [bum.html] line 1: found a non-unique fragment identifier: [another]",
56+
assertEquals("Parser error in template [bum.html:1]: found a non-unique fragment identifier: [another]",
5757
expected.getMessage());
5858
}
5959

@@ -120,7 +120,7 @@ public void testInvalidId() {
120120
() -> engine.parse("{#fragment id='another and foo'}{/}", null, "bum.html"));
121121
assertEquals(FragmentSectionHelper.Code.INVALID_FRAGMENT_ID, expected.getCode());
122122
assertEquals(
123-
"Parser error in template [bum.html] line 1: found an invalid fragment identifier [another and foo] - an identifier can only consist of alphanumeric characters and underscores",
123+
"Parser error in template [bum.html:1]: found an invalid fragment identifier [another and foo] - an identifier can only consist of alphanumeric characters and underscores",
124124
expected.getMessage());
125125
}
126126

0 commit comments

Comments
 (0)