Skip to content

Commit

Permalink
Look behind LIKE operator before performing percent escape
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Nov 7, 2024
1 parent db93dec commit 2a0dee2
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions mug-guava/src/main/java/com/google/mu/safesql/SafeSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,13 @@ private boolean lookaround(
ImmutableList<String> lookahead = TOKENS.from(rightPattern).collect(toImmutableList());
int closingBraceIndex = placeholder.index() + placeholder.length() - 1;
int nextTokenIndex = charIndexToTokenIndex.get(closingBraceIndex) + 1;
ImmutableList<Substring.Match> rightTokens =
allTokens.subList(nextTokenIndex, allTokens.size());
return BiStream.zip(lookahead, rightTokens)
return BiStream.zip(lookahead, allTokens.subList(nextTokenIndex, allTokens.size()))
.filter((s, t) -> s.equalsIgnoreCase(t.toString()))
.count() == lookahead.size()
&& lookbehind(leftPattern, placeholder);
}

private boolean lookbehind(
String leftPattern, Substring.Match placeholder) {
private boolean lookbehind(String leftPattern, Substring.Match placeholder) {
ImmutableList<String> lookbehind = TOKENS.from(leftPattern).collect(toImmutableList());
ImmutableList<Substring.Match> leftTokens =
allTokens.subList(0, charIndexToTokenIndex.get(placeholder.index()));
Expand Down

0 comments on commit 2a0dee2

Please sign in to comment.