Skip to content

Commit 5aba123

Browse files
Dockerelmp911de
authored andcommitted
Replace regex with startsWith / endsWith check for LIKE pattern detection.
Signed-off-by: Giheon Do <dgh0001@naver.com> Closes #3932
1 parent c99c3c2 commit 5aba123

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/ParameterBinding.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ static class LikeParameterBinding extends ParameterBinding {
370370
private static final List<Type> SUPPORTED_TYPES = Arrays.asList(Type.CONTAINING, Type.STARTING_WITH,
371371
Type.ENDING_WITH, Type.LIKE);
372372

373+
private static final String PERCENT = "%";
374+
373375
private final Type type;
374376

375377
/**
@@ -464,15 +466,15 @@ static Type getLikeTypeFrom(String expression) {
464466

465467
Assert.hasText(expression, "Expression must not be null or empty");
466468

467-
if (expression.matches("%.*%")) {
469+
if (expression.startsWith(PERCENT) && expression.endsWith(PERCENT)) {
468470
return Type.CONTAINING;
469471
}
470472

471-
if (expression.startsWith("%")) {
473+
if (expression.startsWith(PERCENT)) {
472474
return Type.ENDING_WITH;
473475
}
474476

475-
if (expression.endsWith("%")) {
477+
if (expression.endsWith(PERCENT)) {
476478
return Type.STARTING_WITH;
477479
}
478480

0 commit comments

Comments
 (0)