Skip to content

Commit

Permalink
Qute: fix validation of an expression with "logical or"
Browse files Browse the repository at this point in the history
- fixes #46476
  • Loading branch information
mkouba committed Feb 26, 2025
1 parent 1ba5ca1 commit 877633d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static List<Info> create(Expression expression, IndexView index, Function<String

static Info create(String typeInfo, Expression.Part part, IndexView index, Function<String, String> templateIdToPathFun,
Origin expressionOrigin) {
if (typeInfo.startsWith(TYPE_INFO_SEPARATOR)) {
if (typeInfo.startsWith(TYPE_INFO_SEPARATOR) && typeInfo.endsWith(TYPE_INFO_SEPARATOR)) {
int endIdx = typeInfo.substring(1, typeInfo.length()).indexOf(Expressions.TYPE_INFO_SEPARATOR);
if (endIdx < 1) {
throw new IllegalArgumentException("Invalid type info: " + typeInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TemplateGlobalTest {
.withApplicationRoot(root -> root
.addClasses(Globals.class, NextGlobals.class)
.addAsResource(new StringAsset(
"Hello {currentUser}|{global:currentUser}! Your name is {_name}|{global:_name}. You're {age}|{global:age} years old."),
"Hello {currentUser}|{global:currentUser}! Your name is {_name}|{global:_name}. You're {age}|{global:age} years old. [{serviceEnabled || true}]"),
"templates/hello.txt"));

@Inject
Expand All @@ -42,13 +42,13 @@ public void testTemplateData() {
assertEquals("Hello 40!", instance.render());
assertTrue(Globals.AGE_USED.get());

assertEquals("Hello Fu|Fu! Your name is Lu|Lu. You're 40|40 years old.", hello.render());
assertEquals("Hello Fu|Fu! Your name is Lu|Lu. You're 40|40 years old. [true]", hello.render());
assertEquals("Hello Fu|Fu! Your name is Lu|Lu. You're 40|40 years old.",
Qute.fmt(
"Hello {currentUser}|{global:currentUser}! Your name is {_name}|{global:_name}. You're {age}|{global:age} years old.")
.render());
Globals.user = "Hu";
assertEquals("Hello Hu|Hu! Your name is Lu|Lu. You're 20|20 years old.", hello.render());
assertEquals("Hello Hu|Hu! Your name is Lu|Lu. You're 20|20 years old. [true]", hello.render());
assertEquals("Hello Hu|Hu! Your name is Lu|Lu. You're 20|20 years old.",
Qute.fmt(
"Hello {currentUser}|{global:currentUser}! Your name is {_name}|{global:_name}. You're {age}|{global:age} years old.")
Expand All @@ -70,6 +70,11 @@ static int age() {
return user.equals("Fu") ? 40 : 20;
}

@TemplateGlobal
static boolean serviceEnabled() {
return true;
}

}

static enum Color {
Expand Down

0 comments on commit 877633d

Please sign in to comment.