Skip to content

Commit 3619539

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

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
@@ -68,8 +68,13 @@ public class ParameterBindingJsonReader extends AbstractBsonReader {
6868
private static final Pattern PARAMETER_BINDING_PATTERN = Pattern.compile("\\?(\\d+)");
6969
private static final Pattern EXPRESSION_BINDING_PATTERN = Pattern.compile("[\\?:][#$]\\{.*\\}");
7070
private static final Pattern SPEL_PARAMETER_BINDING_PATTERN = Pattern.compile("('\\?(\\d+)'|\\?(\\d+))");
71+
7172
private static final String QUOTE_START = "\\Q";
73+
private static final String ESCAPED_QUOTE_START = "\\" + QUOTE_START;
74+
private static final String QUOTE_REPLACEMENT_QUOTE_START = Matcher.quoteReplacement(ESCAPED_QUOTE_START);
7275
private static final String QUOTE_END = "\\E";
76+
private static final String ESCAPED_QUOTE_END = "\\" + QUOTE_END;
77+
private static final String QUOTE_REPLACEMENT_QUOTE_END = Matcher.quoteReplacement(ESCAPED_QUOTE_END);
7378

7479
private final ParameterBindingContext bindingContext;
7580

@@ -421,7 +426,7 @@ private BindableValue bindableValueFor(JsonToken token) {
421426

422427
Matcher regexMatcher = EXPRESSION_BINDING_PATTERN.matcher(computedValue);
423428

424-
while (regexMatcher.find()) {
429+
if (regexMatcher.find()) {
425430

426431
String binding = regexMatcher.group();
427432
String expression = binding.substring(3, binding.length() - 1);
@@ -461,8 +466,8 @@ private BindableValue bindableValueFor(JsonToken token) {
461466

462467
String bindValue = nullSafeToString(getBindableValueForIndex(index));
463468
if(isQuoted(tokenValue)) {
464-
bindValue = bindValue.replaceAll("\\%s".formatted(QUOTE_START), Matcher.quoteReplacement("\\%s".formatted(QUOTE_START))) //
465-
.replaceAll("\\%s".formatted(QUOTE_END), Matcher.quoteReplacement("\\%s".formatted(QUOTE_END)));
469+
bindValue = bindValue.replaceAll(ESCAPED_QUOTE_START, QUOTE_REPLACEMENT_QUOTE_START) //
470+
.replaceAll(ESCAPED_QUOTE_END, QUOTE_REPLACEMENT_QUOTE_END);
466471
}
467472
computedValue = computedValue.replace(group, bindValue);
468473
}

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
@@ -728,7 +728,7 @@ void findByFirstnameStartingWithIgnoreCase() {
728728
assertThat(result.get(0)).isEqualTo(dave);
729729
}
730730

731-
@Test // DATAMONGO-770
731+
@Test
732732
void findByFirstnameStartingWith() {
733733

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

0 commit comments

Comments
 (0)