From 7e5f3e4480537e888ddd11c32d7f77cbb5af596e Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Wed, 8 Dec 2021 15:28:29 +0100 Subject: [PATCH] Qute - fix section parameters parser - fix the problem with a virtual method that has a parameter with leading/trailing spaces - resolves #21858 --- .../core/src/main/java/io/quarkus/qute/Parser.java | 9 ++++++++- .../src/test/java/io/quarkus/qute/ExpressionTest.java | 6 +++++- .../src/test/java/io/quarkus/qute/ParserTest.java | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) 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 fa4461a393a56..f3a873c62c531 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 @@ -640,6 +640,7 @@ static Iterator splitSectionParams(String content, Function parts = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); @@ -648,7 +649,7 @@ static Iterator splitSectionParams(String content, Function 0) { parts.add(buffer.toString()); buffer = new StringBuilder(); @@ -669,6 +670,12 @@ && isCompositeStart(c) && (i == 0 || space || composite > 0 } else if (!stringLiteral && isCompositeEnd(c) && composite > 0) { composite--; + } else if (!stringLiteral + && Parser.isLeftBracket(c)) { + brackets++; + } else if (!stringLiteral + && Parser.isRightBracket(c) && brackets > 0) { + brackets--; } space = false; buffer.append(c); diff --git a/independent-projects/qute/core/src/test/java/io/quarkus/qute/ExpressionTest.java b/independent-projects/qute/core/src/test/java/io/quarkus/qute/ExpressionTest.java index 1aa43522987df..19e919b31726e 100644 --- a/independent-projects/qute/core/src/test/java/io/quarkus/qute/ExpressionTest.java +++ b/independent-projects/qute/core/src/test/java/io/quarkus/qute/ExpressionTest.java @@ -70,7 +70,11 @@ public void testExpressions() throws InterruptedException, ExecutionException { @Test public void testNestedVirtualMethods() { - Expression exp = ExpressionImpl.from("movie.findServices(movie.name,movie.toNumber(movie.getName))"); + assertNestedVirtualMethod(ExpressionImpl.from("movie.findServices(movie.name,movie.toNumber(movie.getName))")); + assertNestedVirtualMethod(ExpressionImpl.from("movie.findServices(movie.name, movie.toNumber(movie.getName) )")); + } + + private void assertNestedVirtualMethod(Expression exp) { assertNull(exp.getNamespace()); List parts = exp.getParts(); assertEquals(2, parts.size()); 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 1a12c2952f0c3..8b1b2c7b40692 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 @@ -188,6 +188,8 @@ public void testSectionParameters() { "false"); assertParams("(item.name == 'foo') and (item.name is false)", "(item.name == 'foo')", "and", "(item.name is false)"); assertParams("(item.name != 'foo') || (item.name == false)", "(item.name != 'foo')", "||", "(item.name == false)"); + assertParams("foo.codePointCount(0, foo.length) baz=bar", "foo.codePointCount(0, foo.length)", "baz=bar"); + assertParams("foo.codePointCount( 0 , foo.length( 1)) baz=bar", "foo.codePointCount( 0 , foo.length( 1))", "baz=bar"); } @Test @@ -372,6 +374,15 @@ public void testInvalidParamDeclaration() { "Parser error on line 1: invalid parameter declaration {@\n}", 1); } + @Test + public void testUserTagVirtualMethodParam() { + Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()) + .addSectionHelper(new UserTagSectionHelper.Factory("form", "form-template")).build(); + engine.putTemplate("form-template", engine.parse("{it}")); + Template foo = engine.parse("{#form foo.codePointCount(0, foo.length) /}"); + assertEquals("3", foo.data("foo", "foo").render()); + } + public static class Foo { public List getItems() {