File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
main/java/com/github/jknack/handlebars/internal/path
test/java/com/github/jknack/handlebars/i1163 Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 55 */
66package com .github .jknack .handlebars .internal .path ;
77
8+ import java .util .List ;
9+ import java .util .Set ;
10+
811import com .github .jknack .handlebars .Context ;
912import com .github .jknack .handlebars .PathExpression ;
1013import com .github .jknack .handlebars .ValueResolver ;
1821 */
1922public class DataPath implements PathExpression {
2023
24+ /** First and last are special in 21. */
25+ private static final Set <String > FIXED = Set .of ("@last" , "@first" );
26+
2127 /** Property name. */
2228 private String name ;
2329
@@ -40,8 +46,15 @@ public Object eval(
4046 // with @
4147 Object value = resolver .resolve (data , name );
4248 if (value == null ) {
43- // without @
44- value = resolver .resolve (data , nameWithoutAtSymbol );
49+ if (data instanceof List ) {
50+ if (!FIXED .contains (name )) {
51+ // without @
52+ value = resolver .resolve (data , nameWithoutAtSymbol );
53+ }
54+ } else {
55+ // without @
56+ value = resolver .resolve (data , nameWithoutAtSymbol );
57+ }
4558 }
4659 return chain .next (resolver , context , value );
4760 }
Original file line number Diff line number Diff line change 1+ /*
2+ * Handlebars.java: https://github.com/jknack/handlebars.java
3+ * Apache License Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
4+ * Copyright (c) 2012 Edgar Espina
5+ */
6+ package com .github .jknack .handlebars .i1163 ;
7+
8+ import java .awt .*;
9+ import java .io .IOException ;
10+ import java .util .List ;
11+
12+ import org .junit .jupiter .api .Test ;
13+
14+ import com .github .jknack .handlebars .AbstractTest ;
15+
16+ public class Issue1163 extends AbstractTest {
17+
18+ @ Test
19+ public void shouldNotFailOnEmptyList () throws IOException {
20+ shouldCompileTo ("{{@last}}" , List .of (), "" );
21+ shouldCompileTo ("{{@first}}" , List .of (), "" );
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments