Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute - fix validation of expressions with the "cdi" namespace #32302

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ static Match validateNestedExpressions(QuteConfig config, TemplateAnalysis templ
BeanInfo bean = findBean(expression, index, incorrectExpressions, namedBeans);
if (bean != null) {
rootClazz = bean.getImplClazz();
// Skip the first part - the name of the bean, e.g. for {inject:foo.name} we start validation with "name"
match.setValues(rootClazz, bean.getProviderType());
} else {
// Bean not found
return putResult(match, results, expression);
Expand Down Expand Up @@ -1197,8 +1199,15 @@ static Match validateNestedExpressions(QuteConfig config, TemplateAnalysis templ
}
} else {
if (INJECT_NAMESPACE.equals(namespace) || CDI_NAMESPACE.equals(namespace)) {
// Skip the first part - the name of the bean, e.g. for {inject:foo.name} we start validation with "name"
match.setValues(rootClazz, Type.create(rootClazz.name(), org.jboss.jandex.Type.Kind.CLASS));
if (root.hasHints()) {
// Root is not a type info but a property with hint
// E.g. 'it<loop#123>' and 'STATUS<when#123>'
if (processHints(templateAnalysis, root.asHintInfo().hints, match, index, expression,
generatedIdsToMatches, incorrectExpressions)) {
// In some cases it's necessary to reset the iterator
iterator = parts.iterator();
}
}
} else if (templateData != null) {
// Set the root type and reset the iterator
match.setValues(rootClazz, Type.create(rootClazz.name(), org.jboss.jandex.Type.Kind.CLASS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;

Expand All @@ -26,6 +27,7 @@ public class NamedBeanIterableReturnTypeTest {
"{@java.lang.String field}"
+ "{#if cdi:validation.hasViolations(field)}"
+ "{#each cdi:validation.getViolations(field)}{it}{/each}"
+ "{#each cdi:violations}:{it.toUpperCase}{/each}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would previously fail during validation...

+ "{/if}"),
"templates/validate.html"));

Expand All @@ -34,7 +36,7 @@ public class NamedBeanIterableReturnTypeTest {

@Test
public void testResult() {
assertEquals("Foo!", validate.data("field", "foo").render());
assertEquals("Foo!:BAR:BAZ", validate.data("field", "foo").render());
}

@ApplicationScoped
Expand All @@ -48,6 +50,12 @@ public boolean hasViolations(String field) {
public List<String> getViolations(String field) {
return List.of("Foo!");
}

@Named("violations")
@Produces
public List<String> getViolations() {
return List.of("bar", "baz");
}
}

}