File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
spring-expression/src/test/java/org/springframework/expression/spel Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -536,6 +536,14 @@ void indexIntoMap() {
536
536
assertCanCompile (expression );
537
537
assertThat (expression .getValue (map )).isEqualTo (111 );
538
538
assertThat (getAst ().getExitDescriptor ()).isEqualTo ("Ljava/lang/Object" );
539
+
540
+ // String key not enclosed in single quotes
541
+ expression = parser .parseExpression ("[aaa]" );
542
+
543
+ assertThat (expression .getValue (map )).isEqualTo (111 );
544
+ assertCanCompile (expression );
545
+ assertThat (expression .getValue (map )).isEqualTo (111 );
546
+ assertThat (getAst ().getExitDescriptor ()).isEqualTo ("Ljava/lang/Object" );
539
547
}
540
548
541
549
@ Test
@@ -644,6 +652,19 @@ void indexIntoMapOfPrimitiveIntArrayWithCompilableMapAccessor() {
644
652
assertThat (getAst ().getExitDescriptor ()).isEqualTo ("I" );
645
653
}
646
654
655
+ @ Test
656
+ void indexIntoStringCannotBeCompiled () {
657
+ String text = "enigma" ;
658
+
659
+ // "g" is the 4th letter in "enigma" (index 3)
660
+ expression = parser .parseExpression ("[3]" );
661
+
662
+ assertThat (expression .getValue (text )).isEqualTo ("g" );
663
+ assertCannotCompile (expression );
664
+ assertThat (expression .getValue (text )).isEqualTo ("g" );
665
+ assertThat (getAst ().getExitDescriptor ()).isNull ();
666
+ }
667
+
647
668
@ Test
648
669
void indexIntoObject () {
649
670
TestClass6 tc = new TestClass6 ();
You can’t perform that action at this time.
0 commit comments