Skip to content

Commit

Permalink
Merge pull request #36524 from mkouba/qute-relax-cdi-namespace-valida…
Browse files Browse the repository at this point in the history
…tion

Qute: relax cdi/inject namespace validation
  • Loading branch information
mkouba authored Oct 18, 2023
2 parents f679d51 + b1c1668 commit 7794fc7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ private static BeanInfo findBean(Expression expression, IndexView index,
Expression.Part firstPart = expression.getParts().get(0);
if (firstPart.isVirtualMethod()) {
incorrectExpressions.produce(new IncorrectExpressionBuildItem(expression.toOriginalString(),
"The inject: namespace must be followed by a bean name",
"The " + expression.getNamespace() + ": namespace must be followed by a bean name",
expression.getOrigin()));
return null;
}
Expand All @@ -1793,8 +1793,12 @@ private static BeanInfo findBean(Expression expression, IndexView index,
return bean;
} else {
// User is injecting a non-existing bean
incorrectExpressions.produce(new IncorrectExpressionBuildItem(expression.toOriginalString(),
beanName, null, expression.getOrigin()));
if (!expression.toOriginalString().endsWith("or(null)")) {
// Fail unless a safe expression
// Note that foo.val?? becomes foo.val.or(null) during parsing
incorrectExpressions.produce(new IncorrectExpressionBuildItem(expression.toOriginalString(),
beanName, null, expression.getOrigin()));
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.qute.deployment.inject;

import static org.junit.jupiter.api.Assertions.assertEquals;

import jakarta.inject.Inject;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.Template;
import io.quarkus.test.QuarkusUnitTest;

public class NamedBeanNotFoundSafeTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot(root -> root
.addAsResource(new StringAsset("{cdi:ping.val??}"), "templates/ping.html"));

@Inject
Template ping;

@Test
public void testTemplate() {
assertEquals("", ping.render());
}

}

0 comments on commit 7794fc7

Please sign in to comment.