Skip to content

Commit

Permalink
more consistent handling of exact url matching without a path
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Jan 7, 2025
1 parent 45bf1d5 commit f80ef38
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/bin/rbw/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,14 @@ impl DecryptedUri {
rbw::api::UriMatchType::StartsWith => {
url.to_string().starts_with(&self.uri)
}
rbw::api::UriMatchType::Exact => url.to_string() == self.uri,
rbw::api::UriMatchType::Exact => {
if url.path() == "/" {
url.to_string().trim_end_matches('/')
== self.uri.trim_end_matches('/')
} else {
url.to_string() == self.uri
}
}
rbw::api::UriMatchType::RegularExpression => {
let Ok(rx) = regex::Regex::new(&self.uri) else {
return false;
Expand Down Expand Up @@ -3040,12 +3047,26 @@ mod test {
Some(rbw::api::UriMatchType::Exact),
)],
),
make_entry(
"four",
None,
None,
&[("https://four.com", Some(rbw::api::UriMatchType::Exact))],
),
];

assert!(
one_match(entries, "https://one.com/", None, None, 0, false),
"one"
);
assert!(
one_match(entries, "https://one.com", None, None, 0, false),
"one"
);
assert!(
no_matches(entries, "https://one.com/foo", None, None, false),
"one"
);
assert!(
no_matches(entries, "https://login.one.com/", None, None, false),
"one"
Expand Down Expand Up @@ -3106,6 +3127,18 @@ mod test {
no_matches(entries, "https://three.com/", None, None, false),
"three"
);
assert!(
one_match(entries, "https://four.com/", None, None, 3, false),
"four"
);
assert!(
one_match(entries, "https://four.com", None, None, 3, false),
"four"
);
assert!(
no_matches(entries, "https://four.com/foo", None, None, false),
"four"
);
}

#[test]
Expand Down

0 comments on commit f80ef38

Please sign in to comment.