Dont append ? to url when cleaning it (#1716)
This commit is contained in:
parent
f6f169b4eb
commit
3b37ea6c8b
1 changed files with 12 additions and 6 deletions
|
@ -149,12 +149,14 @@ pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean_url_params(mut url: Url) -> Url {
|
pub fn clean_url_params(mut url: Url) -> Url {
|
||||||
let new_query = url
|
if url.query().is_some() {
|
||||||
.query_pairs()
|
let new_query = url
|
||||||
.filter(|q| !CLEAN_URL_PARAMS_REGEX.is_match(&q.0))
|
.query_pairs()
|
||||||
.map(|q| format!("{}={}", q.0, q.1))
|
.filter(|q| !CLEAN_URL_PARAMS_REGEX.is_match(&q.0))
|
||||||
.join("&");
|
.map(|q| format!("{}={}", q.0, q.1))
|
||||||
url.set_query(Some(&new_query));
|
.join("&");
|
||||||
|
url.set_query(Some(&new_query));
|
||||||
|
}
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,5 +171,9 @@ mod tests {
|
||||||
let cleaned = clean_url_params(url);
|
let cleaned = clean_url_params(url);
|
||||||
let expected = Url::parse("https://example.com/path/123?username=randomuser&id=123").unwrap();
|
let expected = Url::parse("https://example.com/path/123?username=randomuser&id=123").unwrap();
|
||||||
assert_eq!(expected.to_string(), cleaned.to_string());
|
assert_eq!(expected.to_string(), cleaned.to_string());
|
||||||
|
|
||||||
|
let url = Url::parse("https://example.com/path/123").unwrap();
|
||||||
|
let cleaned = clean_url_params(url.clone());
|
||||||
|
assert_eq!(url.to_string(), cleaned.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue