-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Version
Tested in 5.0.21 and 6.0.0-prerelease.73 (should be any 5.x and above)
Describe the bug
When performing a query using the LIKE operator, queries containing a combination of % and _ (%_) at the start (e.g., $.field LIKE "%_MyValue") fail to return the expected results. Other cases with % and _ in different positions (e.g., "%value_" or "%value_%") work as expected. Additionally, using escape characters (e.g., "%\_value") resolves the issue, suggesting an issue with how the underscore _ character is being interpreted when it appears at the start of a pattern.
Code to Reproduce
-- Query that does not resolve properly
SELECT * FROM table WHERE $.field LIKE "%_MyValue";
-- Other working examples
SELECT * FROM table WHERE $.field LIKE "%value_";
SELECT * FROM table WHERE $.field LIKE "%value_%";
-- Escaping the underscore works
SELECT * FROM table WHERE $.field LIKE "%\_value";collection.Find(x => x.myField.EndsWith("_value"))Expected behavior
The query $.field LIKE "%_MyValue" should return the expected results, treating the underscore _ as a literal character, similar to how queries with other combinations of % and _ work. Ideally, the system should automatically escape the underscore when it appears at the start of the pattern, e.g., converting $.field LIKE "%_MyValue" to $.field LIKE "%\_MyValue", to avoid manual intervention.
Screenshots/Stacktrace
Image 1 - All items

Image 2 - Items containing a word that ends with underscore

Image 3 - Items containing a word that starts with underscore

Image 5 - Items containing a word that starts with underscore but escaped
