Skip to content

Commit

Permalink
Merge pull request #105 from Lurk/unwrap_exit_bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurk authored Sep 23, 2023
2 parents 7c52ff6 + f0757f6 commit b95dd03
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/clink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ impl Clink {
let domain = l.domain().unwrap_or("");
let path = join_url(domain, l.path());
if let Some(params) = self.exit_map.get(&path) {
return l
let exit = l
.query_pairs()
.filter(|p| params.contains(&p.0.clone().into()))
.map(|p| p.1.to_string())
.take(1)
.collect::<String>();
if !exit.is_empty() {
return exit;
}
}
url.to_string()
}
Expand Down Expand Up @@ -270,8 +273,8 @@ mod unwrap_exit_params {
let clink = Clink::new(ClinkConfig::default());
assert_eq!(
clink.unwrap_exit_params(
"https://exit.sc/?url=https%3A%2F%2Fopen.spotify.com%2Fartist%2F3tEV3J5gW5BDMrJqE3NaBy%3Fsi%3D1mLk6MZSRGuol8rgwCe_Cg"
),
"https://exit.sc/?url=https%3A%2F%2Fopen.spotify.com%2Fartist%2F3tEV3J5gW5BDMrJqE3NaBy%3Fsi%3D1mLk6MZSRGuol8rgwCe_Cg"
),
"https://open.spotify.com/artist/3tEV3J5gW5BDMrJqE3NaBy?si=1mLk6MZSRGuol8rgwCe_Cg"
);

Expand All @@ -293,6 +296,15 @@ mod unwrap_exit_params {
"https://open.spotify.com/artist/3tEV3J5gW5BDMrJqE3NaBy?si=1mLk6MZSRGuol8rgwCe_Cg"
);
}

#[test]
fn has_exit_url_but_no_exit_param() {
let clink = Clink::new(ClinkConfig::default());
assert_eq!(
clink.unwrap_exit_params("https://exit.sc/?foo=bar"),
"https://exit.sc/?foo=bar"
);
}
}

#[cfg(test)]
Expand Down

0 comments on commit b95dd03

Please sign in to comment.