Skip to content

Commit 4a3518b

Browse files
committed
Polishing
1 parent dd4a347 commit 4a3518b

File tree

2 files changed

+70
-74
lines changed

2 files changed

+70
-74
lines changed

spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,17 +127,6 @@ void safeNavigation() {
127127
evaluate("null?.null?.null", null, null);
128128
}
129129

130-
@Test // SPR-16731
131-
void matchesWithPatternAccessThreshold() {
132-
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$";
133-
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches \'" + pattern + "\'";
134-
Expression expr = parser.parseExpression(expression);
135-
assertThatExceptionOfType(SpelEvaluationException.class)
136-
.isThrownBy(expr::getValue)
137-
.withCauseInstanceOf(IllegalStateException.class)
138-
.satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.FLAWED_PATTERN));
139-
}
140-
141130
// mixing operators
142131
@Test
143132
void mixingOperators() {
@@ -462,28 +451,35 @@ void relOperatorsInstanceof06() {
462451
}
463452

464453
@Test
465-
void relOperatorsMatches01() {
454+
void matchesTrue() {
455+
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class);
456+
}
457+
458+
@Test
459+
void matchesFalse() {
466460
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class);
467461
}
468462

469463
@Test
470-
void relOperatorsMatches02() {
471-
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class);
464+
void matchesWithInputConversion() {
465+
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int --> string
472466
}
473467

474468
@Test
475-
void relOperatorsMatches03() {
469+
void matchesWithNullInput() {
476470
evaluateAndCheckError("null matches '^.*$'", SpelMessage.INVALID_FIRST_OPERAND_FOR_MATCHES_OPERATOR, 0, null);
477471
}
478472

479473
@Test
480-
void relOperatorsMatches04() {
474+
void matchesWithNullPattern() {
481475
evaluateAndCheckError("'abc' matches null", SpelMessage.INVALID_SECOND_OPERAND_FOR_MATCHES_OPERATOR, 14, null);
482476
}
483477

484-
@Test
485-
void relOperatorsMatches05() {
486-
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string
478+
@Test // SPR-16731
479+
void matchesWithPatternAccessThreshold() {
480+
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$";
481+
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches '" + pattern + "'";
482+
evaluateAndCheckError(expression, SpelMessage.FLAWED_PATTERN);
487483
}
488484

489485
}

0 commit comments

Comments
 (0)