Skip to content

Commit

Permalink
Merge pull request #28051 from mkouba/qute-bracket-notation-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 19, 2022
2 parents 5d758ec + 822edb7 commit 18a6979
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,6 @@ static ExpressionImpl parseExpression(Supplier<Integer> idGenerator, String valu
Iterator<String> strPartsIterator = strParts.iterator();
while (strPartsIterator.hasNext()) {
Part part = createPart(idGenerator, namespace, first, strPartsIterator, scope, origin, value);
if (!isValidIdentifier(part.getName())) {
throw error(ParserError.INVALID_IDENTIFIER, "invalid identifier found [{value}]", origin)
.argument("value", value)
.build();
}
if (first == null) {
first = part;
}
Expand Down Expand Up @@ -980,6 +975,12 @@ private static Part createPart(Supplier<Integer> idGenerator, String namespace,
.argument("value", value)
.build();
}
} else {
if (!isValidIdentifier(value)) {
throw error(ParserError.INVALID_IDENTIFIER, "invalid identifier found [{value}]", origin)
.argument("value", value)
.build();
}
}

String typeInfo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ public void tesMapResolver() {
Map<String, String> map = new LinkedHashMap<>();
map.put("name", "Lu");
map.put("foo.bar", "Ondrej");
map.put("foo and bar", "Bug");

Engine engine = Engine.builder()
.addSectionHelper(new LoopSectionHelper.Factory())
.addDefaultValueResolvers()
.build();
Engine engine = Engine.builder().addDefaults().build();

assertEquals("Lu,Lu,2,false,true,namefoo.bar::Ondrej,Ondrej",
assertEquals("Lu,Lu,3,false,true,[name,foo.bar,foo and bar],Ondrej,Ondrej,Bug",
engine.parse(
"{this.name},{this['name']},{this.size},{this.empty},{this.containsKey('name')},"
+ "{#each this.keys}{it}{/each}"
+ "::{this.get('foo.bar')},{this['foo.bar']}")
"{this.name},"
+ "{this['name']},"
+ "{this.size},"
+ "{this.empty},"
+ "{this.containsKey('name')},"
+ "[{#each this.keys}{it}{#if it_hasNext},{/if}{/each}],"
+ "{this.get('foo.bar')},"
+ "{this['foo.bar']},"
+ "{this['foo and bar']}")
.render(map));
}

Expand Down

0 comments on commit 18a6979

Please sign in to comment.