Fix handling of URI fragments when a URI has no query component

This commit is contained in:
Agatha Lovelace 2024-01-11 21:43:34 +01:00
parent df3e4f09cb
commit 4b0b4ef248
Signed by: sorceress
GPG Key ID: 01D0B3AB10CED4F8
1 changed files with 6 additions and 4 deletions

View File

@ -61,6 +61,11 @@ fn clean_url(text: String, patterns: Vec<String>) -> Result<String, String> {
return Err(format!("URL {url_inner} does not have a host"));
};
// Handle URLs without query parameters
if url.query().is_none() {
return Ok(url.to_string());
}
for pattern in &patterns {
let url_inner = url.clone();
if let Some((param, domain)) = pattern.split_once('@') {
@ -82,8 +87,5 @@ fn clean_url(text: String, patterns: Vec<String>) -> Result<String, String> {
}
}
// Handle dangling ?s when no query pairs are appended
let url = url.as_str().trim_end_matches('?').to_owned();
Ok(url)
Ok(url.to_string())
}