Skip to content

Commit 472e367

Browse files
schauderchristophstrobl
authored andcommitted
Polishing.
Minor formatting. Replaced a while loop that ends with a return with an if. See: #5095
1 parent f2ca3b3 commit 472e367

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReader.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ public class ParameterBindingJsonReader extends AbstractBsonReader {
7070
private static final Pattern PARAMETER_BINDING_PATTERN = Pattern.compile("\\?(\\d+)");
7171
private static final Pattern EXPRESSION_BINDING_PATTERN = Pattern.compile("[\\?:][#$]\\{.*\\}");
7272
private static final Pattern SPEL_PARAMETER_BINDING_PATTERN = Pattern.compile("('\\?(\\d+)'|\\?(\\d+))");
73+
7374
private static final String QUOTE_START = "\\Q";
75+
private static final String ESCAPED_QUOTE_START = "\\" + QUOTE_START;
76+
private static final String QUOTE_REPLACEMENT_QUOTE_START = Matcher.quoteReplacement(ESCAPED_QUOTE_START);
7477
private static final String QUOTE_END = "\\E";
78+
private static final String ESCAPED_QUOTE_END = "\\" + QUOTE_END;
79+
private static final String QUOTE_REPLACEMENT_QUOTE_END = Matcher.quoteReplacement(ESCAPED_QUOTE_END);
7580

7681
private final ParameterBindingContext bindingContext;
7782

@@ -423,7 +428,7 @@ private BindableValue bindableValueFor(JsonToken token) {
423428

424429
Matcher regexMatcher = EXPRESSION_BINDING_PATTERN.matcher(computedValue);
425430

426-
while (regexMatcher.find()) {
431+
if (regexMatcher.find()) {
427432

428433
String binding = regexMatcher.group();
429434
String expression = binding.substring(3, binding.length() - 1);
@@ -463,8 +468,8 @@ private BindableValue bindableValueFor(JsonToken token) {
463468

464469
String bindValue = nullSafeToString(getBindableValueForIndex(index));
465470
if(isQuoted(tokenValue)) {
466-
bindValue = bindValue.replaceAll("\\%s".formatted(QUOTE_START), Matcher.quoteReplacement("\\%s".formatted(QUOTE_START))) //
467-
.replaceAll("\\%s".formatted(QUOTE_END), Matcher.quoteReplacement("\\%s".formatted(QUOTE_END)));
471+
bindValue = bindValue.replaceAll(ESCAPED_QUOTE_START, QUOTE_REPLACEMENT_QUOTE_START) //
472+
.replaceAll(ESCAPED_QUOTE_END, QUOTE_REPLACEMENT_QUOTE_END);
468473
}
469474
computedValue = computedValue.replace(group, bindValue);
470475
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ void findByFirstnameStartingWithIgnoreCase() {
826826
assertThat(result.get(0)).isEqualTo(dave);
827827
}
828828

829-
@Test // DATAMONGO-770
829+
@Test
830830
void findByFirstnameStartingWith() {
831831

832832
String inputString = "\\E.*\\Q";

0 commit comments

Comments
 (0)