-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Convert Go regex to Rust regex #76
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Changes have been made to critical files, which contain lines commonly executed in production. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 98.88% 98.90% +0.01%
==========================================
Files 14 14
Lines 6126 6215 +89
==========================================
+ Hits 6058 6147 +89
Misses 68 68
☔ View full report in Codecov by Sentry. |
Go and Rust have some differences in their regex implementation. In Go the following is valid: ``` uri=~"/v[1-9]/.*/{gid}/{uid}" ``` Rust sees the `{gid}` as a bad repetition, it expects a range like {1,4} ``` regex parse error: /v[1-9]/.*/{gid}/{uid} ^ error: repetition quantifier expects a valid decimal ``` For it to be a valid Rust regex the opening { has to be escaped. This change adds that escaping. The implementation is simple, iteration + writing in a result buffer. It is probably not the best of nicest way of doing it, but it straight forward
Looks like we only need to convert the The problem is the difference between Go and Rust in handling repetition sequence and bracket literal. Go treats For example, for |
Yes thats basically what this MR does, Go 'auto escapes' the sequence while Rust doesn't. So the conversion is |
Should |
I'm interested in the escaping of |
I'm not entirely sure what you mean. In my testing just escaping the
|
Thanks for your contribution @fbs ❤️ |
Thanks for the quick review team! <3. I wonder if there are more regex incompatibility issues in this. |
I will watch on this, thanks for your contribution 😀 |
Go and Rust have some differences in their regex implementation. In Go the following is valid:
Rust sees the
{gid}
as a bad repetition, it expects a range like {1,4}For it to be a valid Rust regex the opening { has to be escaped.
This change adds that escaping.
The implementation is simple, iteration + writing in a result buffer. It is probably not the best of nicest way of doing it, but it straight forward.
Fixes #75