Skip to content

Commit ed2a9e2

Browse files
committed
feat: fix like on colleciton name on mongodb
Signed-off-by: Otavio Santana <[email protected]>
1 parent e25fbdf commit ed2a9e2

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

jnosql-mongodb/src/main/java/org/eclipse/jnosql/databases/mongodb/communication/DocumentQueryConversor.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,24 @@ public static Bson convert(CriteriaCondition condition) {
8080
}
8181

8282
public static String prepareRegexValue(String rawData) {
83-
if (rawData == null)
84-
return "^$";
85-
return "^" + rawData
86-
.replaceAll("_", ".{1}")
87-
.replaceAll("%", ".{1,}");
83+
if (rawData == null) {
84+
return "(?!)"; // matches nothing
85+
}
86+
StringBuilder sb = new StringBuilder("^");
87+
for (char c : rawData.toCharArray()) {
88+
switch (c) {
89+
case '%': // SQL LIKE: zero or more
90+
sb.append(".*");
91+
break;
92+
case '_': // SQL LIKE: exactly one
93+
sb.append('.');
94+
break;
95+
default: // escape all regex meta characters
96+
sb.append(Pattern.quote(String.valueOf(c)));
97+
}
98+
}
99+
sb.append('$');
100+
return sb.toString();
88101
}
89102

90103
}

0 commit comments

Comments
 (0)