Skip to content

Commit a37972e

Browse files
authored
Merge pull request #47136 from mkouba/issue-47132
Qute: section parameters are now separated by one or more whitespaces
2 parents 1ecf476 + 1f0e013 commit a37972e

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

docs/src/main/asciidoc/qute-reference.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ Some sections support optional end tags, i.e. if the end tag is missing then the
652652
==== Parameters
653653

654654
A start tag can define parameters with optional names, e.g. `{#if item.isActive}` and `{#let foo=1 bar=false}`.
655-
Parameters are separated by one or more spaces.
655+
Parameters are separated by one or more whitespaces.
656656
Names are separated from the values by the equals sign.
657657
Names and values can be prefixed and suffixed with any number of spaces, e.g. `{#let id='Foo'}` and `{#let id = 'Foo'}` are equivalents where the name of the parameter is `id` and the value is `Foo`.
658658
Values can be grouped using parentheses, e.g. `{#let id=(item.id ?: 42)}` where the name is `id` and the value is `item.id ?: 42`.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,14 +821,14 @@ static <B extends ErrorInitializer & WithOrigin> Iterator<String> splitSectionPa
821821
boolean stringLiteralDouble = false;
822822
short composite = 0;
823823
byte brackets = 0;
824-
boolean space = false;
824+
boolean whitespace = false;
825825
List<String> parts = new ArrayList<>();
826826
StringBuilder buffer = new StringBuilder();
827827

828828
for (int i = 0; i < content.length(); i++) {
829829
char c = content.charAt(i);
830-
if (c == ' ') {
831-
if (!space) {
830+
if (Character.isWhitespace(c)) {
831+
if (!whitespace) {
832832
if (!stringLiteralSingle
833833
&& !stringLiteralDouble
834834
&& composite == 0
@@ -837,7 +837,7 @@ static <B extends ErrorInitializer & WithOrigin> Iterator<String> splitSectionPa
837837
parts.add(buffer.toString());
838838
buffer = new StringBuilder();
839839
}
840-
space = true;
840+
whitespace = true;
841841
} else {
842842
buffer.append(c);
843843
}
@@ -854,7 +854,7 @@ static <B extends ErrorInitializer & WithOrigin> Iterator<String> splitSectionPa
854854
} else if (!stringLiteralSingle
855855
&& !stringLiteralDouble
856856
&& isCompositeStart(c)
857-
&& (i == 0 || space || composite > 0
857+
&& (i == 0 || whitespace || composite > 0
858858
|| (buffer.length() > 0 && buffer.charAt(buffer.length() - 1) == '!'))) {
859859
composite++;
860860
} else if (!stringLiteralSingle
@@ -871,7 +871,7 @@ && isCompositeEnd(c)
871871
&& Parser.isRightBracket(c) && brackets > 0) {
872872
brackets--;
873873
}
874-
space = false;
874+
whitespace = false;
875875
buffer.append(c);
876876
}
877877
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,24 @@ public void testSkipIt() {
243243
assertEquals("foo=\"true\"",
244244
engine.parse("{#arg foo=true 'foo and bar' /}").render());
245245
}
246+
247+
@Test
248+
public void testArgumentsWhitespace() {
249+
Engine engine = Engine.builder()
250+
.addDefaults()
251+
.addValueResolver(new ReflectionValueResolver())
252+
.addSectionHelper(new UserTagSectionHelper.Factory("arg", "arg-tag"))
253+
.addResultMapper(new HtmlEscaper(List.of("text/html")))
254+
.build();
255+
engine.putTemplate("arg-tag", engine.parse("{_args.asHtmlAttributes}::{hash}"));
256+
assertEquals("class=\"rounded\" hash=\"ia3andy\"::ia3andy",
257+
engine.parse("""
258+
{#arg hash='ia3andy' \n\t
259+
class='rounded' /}
260+
""").render().trim());
261+
assertEquals("class=\"rounded\" hash=\"ia3andy\"::ia3andy",
262+
engine.parse("""
263+
{#arg hash='ia3andy'\n\tclass='rounded' /}
264+
""").render().trim());
265+
}
246266
}

0 commit comments

Comments
 (0)