Skip to content

Commit

Permalink
Qute validation - fix the way the namespace expressions are collected
Browse files Browse the repository at this point in the history
- also fixes quarkusio#32355

(cherry picked from commit b5d6e39)
  • Loading branch information
mkouba authored and gsmet committed Apr 18, 2023
1 parent 009f718 commit d021d10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ static void collectNamespaceExpressions(Expression expression, Set<Expression> n
if (expression.isLiteral()) {
return;
}
if (includeNamespaceExpression(expression, namespace)) {
if (namespace.equals(expression.getNamespace())) {
// The expression itself has namespace
namespaceExpressions.add(expression);
}
Expand All @@ -2867,14 +2867,6 @@ static void collectNamespaceExpressions(Expression expression, Set<Expression> n
}
}

private static boolean includeNamespaceExpression(Expression expression, String namespace) {
if (namespace.equals(expression.getNamespace())) {
return true;
}
String typeInfo = expression.getParts().get(0).getTypeInfo();
return typeInfo != null ? typeInfo.startsWith(namespace) : false;
}

public static String getName(InjectionPointInfo injectionPoint) {
if (injectionPoint.isField()) {
return injectionPoint.getTarget().asField().name();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package io.quarkus.qute.deployment;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import org.junit.jupiter.api.Test;

import io.quarkus.qute.Engine;
import io.quarkus.qute.Expression;
import io.quarkus.qute.Template;
import io.quarkus.qute.deployment.TemplatesAnalysisBuildItem.TemplateAnalysis;

public class QuteProcessorTest {

@Test
Expand All @@ -26,4 +34,24 @@ public void testTemplateDataIgnorePattern() {
.isThrownBy(() -> QuteProcessor.buildIgnorePattern(List.of()));
}

@Test
public void testCollectNamespaceExpressions() {
Template template = Engine.builder().build().parse("{msg:hello} {msg2:hello_alpha} {foo:baz.get(foo:bar)}");
TemplateAnalysis analysis = new TemplateAnalysis("foo", "1", template.getExpressions(), Collections.emptyList(), null);
Set<Expression> msg = QuteProcessor.collectNamespaceExpressions(analysis, "msg");
assertEquals(1, msg.size());
assertEquals("msg:hello", msg.iterator().next().toOriginalString());

Set<Expression> msg2 = QuteProcessor.collectNamespaceExpressions(analysis, "msg2");
assertEquals(1, msg2.size());
assertEquals("msg2:hello_alpha", msg2.iterator().next().toOriginalString());

Set<Expression> foo = QuteProcessor.collectNamespaceExpressions(analysis, "foo");
assertEquals(2, foo.size());
for (Expression fooExpr : foo) {
assertTrue(
fooExpr.toOriginalString().equals("foo:bar") || fooExpr.toOriginalString().equals("foo:baz.get(foo:bar)"));
}
}

}

0 comments on commit d021d10

Please sign in to comment.