fix: correct escape & anchor handling in likeToRegex/regexToLike#1174
Merged
velo merged 2 commits intoOpenFeign:masterfrom Jun 9, 2025
renechoi:fix/like-regex-escape-anchors
Merged
fix: correct escape & anchor handling in likeToRegex/regexToLike#1174velo merged 2 commits intoOpenFeign:masterfrom renechoi:fix/like-regex-escape-anchors
velo merged 2 commits intoOpenFeign:masterfrom
renechoi:fix/like-regex-escape-anchors
Conversation
- treat \% \_ as literals, escape regex metachars, strip outer ^/$ only - add unit tests to guarantee accurate LIKE ↔ regex round-trips
Signed-off-by: Marvin Froeder <[email protected]>
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #1174 +/- ##
============================================
+ Coverage 61.19% 71.03% +9.84%
+ Complexity 84 60 -24
============================================
Files 831 857 +26
Lines 32015 32367 +352
Branches 3590 3606 +16
============================================
+ Hits 19590 22991 +3401
+ Misses 11179 8149 -3030
+ Partials 1246 1227 -19 ☔ View full report in Codecov by Sentry. |
velo
added a commit
that referenced
this pull request
Jun 9, 2025
* Add `TypeWrapperFactoryExpression` for Type-Safe Custom Number Mapping in Querydsl Aggregations (#1181) * Introduce TypeWrapper to wrap Expression results into custom types - Implement TypeWrapper<S, T> as a FactoryExpression - Allows converting a source Expression (e.g. BigDecimal) to a domain type (e.g. Money) - Prepares QueryDSL core to support custom aggregation projections without core API changes * Add JPAQueryCustomTypeWrapperTest covering success and failure scenarios - Verify IllegalArgumentException for unsupported custom types without wrapper - Verify sum-and-wrap to Money via TypeWrapper in both direct and DTO projection use cases - Ensure both positive and negative paths are exercised * Fix: Improve handling of `contains()` on JPA collections mapped with `@Converter` to basic types (#1199) * Fix: Early error for .contains() on @converter mapped JPA collections * Test : add test code * Add test cases to improve test coverage * style: revert formatting change based on review feedback for consistency * fix: correct escape & anchor handling in likeToRegex/regexToLike (#1174) * fix: correct escape & anchor handling in likeToRegex/regexToLike - treat \% \_ as literals, escape regex metachars, strip outer ^/$ only - add unit tests to guarantee accurate LIKE ↔ regex round-trips * Fix code format Signed-off-by: Marvin Froeder <[email protected]> --------- Signed-off-by: Marvin Froeder <[email protected]> Co-authored-by: Marvin Froeder <[email protected]> --------- Signed-off-by: Marvin Froeder <[email protected]> Co-authored-by: 차동민 <[email protected]> Co-authored-by: renechoi <[email protected]> Co-authored-by: Marvin Froeder <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Description
The original implementations of the methods
likeToRegexandregexToLikeinExpressionUtilsdid not properly handle escaped characters (%,_,.,*,?, etc.) and regex anchors (^and$). This caused incorrect translations between SQLLIKEexpressions and regex patterns, potentially leading to faulty queries and unexpected behavior during runtime.Proposed Solution
To address these issues, the following modifications were made:
Handling Escaped Characters:
likeToRegexmethod to correctly interpret escape sequences (e.g.,\%and\_) in the LIKE pattern, ensuring they're preserved as literal characters in the resulting regex.regexToLikemethod to accurately detect and preserve escaped special characters, thereby ensuring that regex patterns translate correctly back to SQL LIKE patterns.Correcting Regex Anchors (
^and$):regexToLiketo trim regex anchor characters (^at the start and$at the end) before conversion, allowing accurate translation into equivalent SQL LIKE patterns.Testing
Comprehensive unit tests were written and added to
ExpressionUtilsTest, verifying that:a\%btranslates to regex^a%b$and vice versa).All tests pass successfully, ensuring the reliability and correctness of the revised methods.
Significance
These corrections significantly enhance the robustness and accuracy of Querydsl's pattern matching utilities. Developers relying on Querydsl for query construction will experience fewer surprises and less unexpected behavior due to properly managed escape sequences and regex anchors.
Practical Improvements in Usage
With these fixes: