Skip to content

Commit

Permalink
feat: add escaping for special db characters in search string criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
milan.horvath committed Jan 11, 2024
1 parent 7d56d64 commit 20ab4b4
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public Predicate createSearchStringPredicate(CriteriaBuilder criteriaBuilder, Ex
public Predicate createSearchStringPredicate(CriteriaBuilder criteriaBuilder, Expression<String> column,
String searchString, final boolean caseInsensitive) {

// escape the extra DB characters
searchString = searchString
.replace("\\", "\\\\")
.replace("%", "\\%")
.replace("_", "\\_");

Expression<String> columnDefinition = column;
if (caseInsensitive) {
searchString = searchString.toLowerCase();
Expand Down

0 comments on commit 20ab4b4

Please sign in to comment.