-
Notifications
You must be signed in to change notification settings - Fork 357
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 bug in wildcard filter where pattern would match in the middle of a string #2076
Conversation
… a string The fix anchors the regex by delimiting it with `^` and `$` so that it only matches the full string and not anywhere in the middle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the super-quick fix @romac! Nicely done! 🙏
|
||
impl Wildcard { | ||
pub fn new(pattern: String) -> Result<Self, regex::Error> { | ||
let escaped = regex::escape(&pattern).replace("\\*", "(?:.*)"); | ||
let regex = format!("^{escaped}$").parse()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of captured identifiers! 💯
@@ -137,28 +137,35 @@ impl Serialize for ChannelFilters { | |||
|
|||
/// Newtype wrapper for expressing wildcard patterns compiled to a [`regex::Regex`]. | |||
#[derive(Clone, Debug)] | |||
pub struct Wildcard(regex::Regex); | |||
pub struct Wildcard { | |||
pattern: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
… a string (informalsystems#2076) * Fix bug in wildcard filter where pattern would match in the middle of a string The fix anchors the regex by delimiting it with `^` and `$` so that it only matches the full string and not anywhere in the middle. * Add changelog entry * Store original pattern inside `Wildcard` instead of re-deriving it from the regex
Closes: #2075
Description
The fix anchors the regex by delimiting it with
^
and$
so that it only matches the full string and not anywhere in the middle.PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.