Skip to content

Commit

Permalink
fix: #341 fixed parameter extraction in @query (resolved gh-346)
Browse files Browse the repository at this point in the history
* #341 fixed the problem of reusing the parameter in @query

* fix regex
  • Loading branch information
justTimTim authored Sep 13, 2023
1 parent 801627c commit 614d603
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ private String prepareQuery(final Object[] parameters) {
v = parameters[index].toString();
}

var regex = "(\\$" + key + ")(\\W+|\\*|\\+)(.*)";
preparedQuery = new StringBuilder(preparedQuery.toString().replaceAll(regex, v + "$2$3"));
String regex = "\\$" + key + "\\b";
preparedQuery = new StringBuilder(preparedQuery.toString().replaceAll(regex, v));
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,14 @@ void testEndingWithSearches() {
);
}

@Test
void testQueryDoubleConditionWhileOneParam() {
Point point1 = new Point(-12.100, 4.640);
MyDoc doc1 = MyDoc.of( id1, point1, point1, 1);
repository.save(doc1);

List<MyDoc> result = repository.searchByIdOrTitle(id1);
assertThat(result).hasSize(2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@
Iterable<MyDoc> findByLocation2Near(Point point, Distance distance);

Iterable<MyDoc> findByaNumber(Integer anotherNumber);

@Query(value = "(@id:{$title}) | (@title:$title)")
List<MyDoc> searchByIdOrTitle(@Param("title") String title);

}

0 comments on commit 614d603

Please sign in to comment.