Skip to content

Commit f92b40c

Browse files
Dockerelmp911de
authored andcommitted
Replace regex with startsWith / endsWith check for LIKE pattern detection.
Signed-off-by: Giheon Do <[email protected]> Closes #3932
1 parent caa4704 commit f92b40c

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
@@ -231,6 +231,8 @@ static class LikeParameterBinding extends ParameterBinding {
231231
private static final List<Type> SUPPORTED_TYPES = Arrays.asList(Type.CONTAINING, Type.STARTING_WITH,
232232
Type.ENDING_WITH, Type.LIKE);
233233

234+
private static final String PERCENT = "%";
235+
234236
private final Type type;
235237

236238
/**
@@ -326,15 +328,15 @@ static Type getLikeTypeFrom(String expression) {
326328

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

329-
if (expression.matches("%.*%")) {
331+
if (expression.startsWith(PERCENT) && expression.endsWith(PERCENT)) {
330332
return Type.CONTAINING;
331333
}
332334

333-
if (expression.startsWith("%")) {
335+
if (expression.startsWith(PERCENT)) {
334336
return Type.ENDING_WITH;
335337
}
336338

337-
if (expression.endsWith("%")) {
339+
if (expression.endsWith(PERCENT)) {
338340
return Type.STARTING_WITH;
339341
}
340342

0 commit comments

Comments
 (0)