-
Notifications
You must be signed in to change notification settings - Fork 424
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 Regex::replacen
when replacing an empty match.
#395
Conversation
Note that i don't know why the CI checks are failing, something seemingly unrelated to this part of the code. |
Bump 🐅... Not sure if I should do anything or not right now! I guess someone would have to review this (actually this is really just a couple line, still I'm not sure about the simplicity of the code but now it's consistent). Note: I rebased on master to enable fast-forward. |
I just ran into this bug. This fix looks correct to me. @BurntSushi, r? |
Right, sorry, forgot about this. LGTM. Thanks so much for the bug fix! @bors r+ |
📌 Commit 408add0 has been approved by |
Fix `Regex::replacen` when replacing an empty match. Fixes #393, #394. There was some logic error when deciding to return `Cow::Borrowed` vs `Cow::Owned` in the fast-path. I took the same solution as the slow-path, ie use `peekable` on the iterator. I'm not sure this is the most efficient way (maybe just add `mut did_replace = false` and set it to true in the loop), but it does the job.
☀️ Test successful - status-appveyor, status-travis |
Fixes #393, #394.
There was some logic error when deciding to return
Cow::Borrowed
vsCow::Owned
in the fast-path. I took the same solution as the slow-path, ie usepeekable
on the iterator. I'm not sure this is the most efficient way (maybe just addmut did_replace = false
and set it to true in the loop), but it does the job.