Tokenizer uses single process step and length-based exhaustion check
Issue: SPR-16032
(cherry picked from commit 03b6828)
This commit is contained in:
@@ -59,6 +59,7 @@ import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeLocator;
|
||||
import org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -228,7 +229,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void SPR5804() throws Exception {
|
||||
Map<String, String> m = new HashMap<String, String>();
|
||||
Map<String, String> m = new HashMap<>();
|
||||
m.put("foo", "bar");
|
||||
StandardEvaluationContext eContext = new StandardEvaluationContext(m); // root is a map instance
|
||||
eContext.addPropertyAccessor(new MapAccessor());
|
||||
@@ -550,7 +551,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
public String floo = "bar";
|
||||
|
||||
public XX() {
|
||||
m = new HashMap<String, String>();
|
||||
m = new HashMap<>();
|
||||
m.put("$foo", "wibble");
|
||||
m.put("bar", "siddle");
|
||||
}
|
||||
@@ -579,7 +580,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
static class Holder {
|
||||
|
||||
public Map<String, String> map = new HashMap<String, String>();
|
||||
public Map<String, String> map = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@@ -783,9 +784,9 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void mapOfMap_SPR7244() throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("uri", "http:");
|
||||
Map<String, String> nameMap = new LinkedHashMap<String, String>();
|
||||
Map<String, String> nameMap = new LinkedHashMap<>();
|
||||
nameMap.put("givenName", "Arthur");
|
||||
map.put("value", nameMap);
|
||||
|
||||
@@ -849,11 +850,11 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
public Map<String, String> ms;
|
||||
|
||||
C() {
|
||||
ls = new ArrayList<String>();
|
||||
ls = new ArrayList<>();
|
||||
ls.add("abc");
|
||||
ls.add("def");
|
||||
as = new String[] { "abc", "def" };
|
||||
ms = new HashMap<String, String>();
|
||||
ms = new HashMap<>();
|
||||
ms.put("abc", "xyz");
|
||||
ms.put("def", "pqr");
|
||||
}
|
||||
@@ -877,7 +878,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void greaterThanWithNulls_SPR7840() throws Exception {
|
||||
List<D> list = new ArrayList<D>();
|
||||
List<D> list = new ArrayList<>();
|
||||
list.add(new D("aaa"));
|
||||
list.add(new D("bbb"));
|
||||
list.add(new D(null));
|
||||
@@ -937,7 +938,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
EvaluationContext emptyEvalContext = new StandardEvaluationContext();
|
||||
|
||||
List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
|
||||
List<TypeDescriptor> args = new ArrayList<>();
|
||||
args.add(TypeDescriptor.forObject(new Integer(42)));
|
||||
|
||||
ConversionPriority1 target = new ConversionPriority1();
|
||||
@@ -977,7 +978,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
WideningPrimitiveConversion target = new WideningPrimitiveConversion();
|
||||
EvaluationContext emptyEvalContext = new StandardEvaluationContext();
|
||||
|
||||
List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
|
||||
List<TypeDescriptor> args = new ArrayList<>();
|
||||
args.add(TypeDescriptor.forObject(INTEGER_VALUE));
|
||||
|
||||
MethodExecutor me = new ReflectiveMethodResolver(true).resolve(emptyEvalContext, target, "getX", args);
|
||||
@@ -990,10 +991,10 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
public void varargsAndPrimitives_SPR8174() throws Exception {
|
||||
EvaluationContext emptyEvalContext = new StandardEvaluationContext();
|
||||
List<TypeDescriptor> args = new ArrayList<TypeDescriptor>();
|
||||
List<TypeDescriptor> args = new ArrayList<>();
|
||||
|
||||
args.add(TypeDescriptor.forObject(34L));
|
||||
ReflectionUtil<Integer> ru = new ReflectionUtil<Integer>();
|
||||
ReflectionUtil<Integer> ru = new ReflectionUtil<>();
|
||||
MethodExecutor me = new ReflectiveMethodResolver().resolve(emptyEvalContext, ru, "methodToCall", args);
|
||||
|
||||
args.set(0, TypeDescriptor.forObject(23));
|
||||
@@ -1113,7 +1114,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
public int DIV = 1;
|
||||
public int div = 3;
|
||||
|
||||
public Map<String, String> m = new HashMap<String, String>();
|
||||
public Map<String, String> m = new HashMap<>();
|
||||
|
||||
Reserver() {
|
||||
m.put("NE", "xyz");
|
||||
@@ -1229,10 +1230,10 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
class ContextObject {
|
||||
|
||||
public Map<String, String> firstContext = new HashMap<String, String>();
|
||||
public Map<String, String> secondContext = new HashMap<String, String>();
|
||||
public Map<String, String> thirdContext = new HashMap<String, String>();
|
||||
public Map<String, String> fourthContext = new HashMap<String, String>();
|
||||
public Map<String, String> firstContext = new HashMap<>();
|
||||
public Map<String, String> secondContext = new HashMap<>();
|
||||
public Map<String, String> thirdContext = new HashMap<>();
|
||||
public Map<String, String> fourthContext = new HashMap<>();
|
||||
|
||||
public ContextObject() {
|
||||
firstContext.put("shouldBeFirst", "first");
|
||||
@@ -1276,7 +1277,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
public void customStaticFunctions_SPR9038() {
|
||||
ExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>();
|
||||
List<MethodResolver> methodResolvers = new ArrayList<>();
|
||||
methodResolvers.add(new ReflectiveMethodResolver() {
|
||||
@Override
|
||||
protected Method[] getMethods(Class<?> type) {
|
||||
@@ -1768,6 +1769,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
result = spel.getValue(context);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.getClass().isArray());
|
||||
@@ -1802,7 +1804,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
public void SPR9194() {
|
||||
TestClass2 one = new TestClass2("abc");
|
||||
TestClass2 two = new TestClass2("abc");
|
||||
Map<String, TestClass2> map = new HashMap<String, TestClass2>();
|
||||
Map<String, TestClass2> map = new HashMap<>();
|
||||
map.put("one", one);
|
||||
map.put("two", two);
|
||||
|
||||
@@ -1813,7 +1815,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
public void SPR11348() {
|
||||
Collection<String> coll = new LinkedHashSet<String>();
|
||||
Collection<String> coll = new LinkedHashSet<>();
|
||||
coll.add("one");
|
||||
coll.add("two");
|
||||
coll = Collections.unmodifiableCollection(coll);
|
||||
@@ -1927,10 +1929,10 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void SPR13055() throws Exception {
|
||||
List<Map<String, Object>> myPayload = new ArrayList<Map<String, Object>>();
|
||||
List<Map<String, Object>> myPayload = new ArrayList<>();
|
||||
|
||||
Map<String, Object> v1 = new HashMap<String, Object>();
|
||||
Map<String, Object> v2 = new HashMap<String, Object>();
|
||||
Map<String, Object> v1 = new HashMap<>();
|
||||
Map<String, Object> v2 = new HashMap<>();
|
||||
|
||||
v1.put("test11", "test11");
|
||||
v1.put("test12", "test12");
|
||||
@@ -1964,7 +1966,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
assertEquals("custard", expr.getValue(context));
|
||||
expr = new SpelExpressionParser().parseRaw("&foo");
|
||||
assertEquals("foo factory",expr.getValue(context));
|
||||
|
||||
|
||||
try {
|
||||
expr = new SpelExpressionParser().parseRaw("&@foo");
|
||||
fail("Illegal syntax, error expected");
|
||||
@@ -1973,7 +1975,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode());
|
||||
assertEquals(0,spe.getPosition());
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
expr = new SpelExpressionParser().parseRaw("@&foo");
|
||||
fail("Illegal syntax, error expected");
|
||||
@@ -1981,7 +1983,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
catch (SpelParseException spe) {
|
||||
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode());
|
||||
assertEquals(0,spe.getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2094,6 +2096,16 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
assertEquals(Charset.forName("UTF-8"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SPR16032() {
|
||||
EvaluationContext context = new StandardEvaluationContext();
|
||||
context.setVariable("str", "a\0b");
|
||||
|
||||
Expression ex = parser.parseExpression("#str?.split('\0')");
|
||||
Object result = ex.getValue(context);
|
||||
assertTrue(ObjectUtils.nullSafeEquals(result, new String[] {"a", "b"}));
|
||||
}
|
||||
|
||||
|
||||
public static class ListOf {
|
||||
|
||||
@@ -2269,7 +2281,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<Item> children = new ArrayList<Item>();
|
||||
private List<Item> children = new ArrayList<>();
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
|
||||
Reference in New Issue
Block a user