Skip to content

Commit

Permalink
Qute: relax cdi/inject namespace validation
Browse files Browse the repository at this point in the history
- do not fail the build if a safe expression is used
  • Loading branch information
mkouba committed Oct 17, 2023
1 parent 0a8efce commit b1c1668
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 b1c1668

Please sign in to comment.