|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -168,39 +168,35 @@ public class EvaluationTests extends AbstractExpressionTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRelOperatorsMatches01() { |
|
|
|
void matchesTrue() { |
|
|
|
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class); |
|
|
|
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRelOperatorsMatches02() { |
|
|
|
void matchesFalse() { |
|
|
|
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class); |
|
|
|
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRelOperatorsMatches03() { |
|
|
|
void matchesWithInputConversion() { |
|
|
|
evaluateAndCheckError("null matches '^.*$'", SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, 0, null); |
|
|
|
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int --> string
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRelOperatorsMatches04() { |
|
|
|
void matchesWithNullInput() { |
|
|
|
evaluateAndCheckError("'abc' matches null", SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, 14, null); |
|
|
|
evaluateAndCheckError("null matches '^.*$'", SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, 0, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRelOperatorsMatches05() { |
|
|
|
void matchesWithNullPattern() { |
|
|
|
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string
|
|
|
|
evaluateAndCheckError("'abc' matches null", SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, 14, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-16731
|
|
|
|
@Test // SPR-16731
|
|
|
|
public void testMatchesWithPatternAccessThreshold() { |
|
|
|
void matchesWithPatternAccessThreshold() { |
|
|
|
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$"; |
|
|
|
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$"; |
|
|
|
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches \'" + pattern + "\'"; |
|
|
|
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches '" + pattern + "'"; |
|
|
|
Expression expr = parser.parseExpression(expression); |
|
|
|
evaluateAndCheckError(expression, SpelMessage.FLAWED_PATTERN); |
|
|
|
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy( |
|
|
|
|
|
|
|
expr::getValue) |
|
|
|
|
|
|
|
.withCauseInstanceOf(IllegalStateException.class) |
|
|
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.FLAWED_PATTERN)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// mixing operators
|
|
|
|
// mixing operators
|
|
|
|
|