mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-18 10:41:06 +00:00
String allocation not needed
This commit is contained in:
parent
f143087743
commit
f47282093a
1 changed files with 8 additions and 17 deletions
|
|
@ -2,12 +2,12 @@ use linkify::LinkFinder;
|
|||
|
||||
/// Remove all GET parameters from a URL.
|
||||
/// The link is not a URL but a String as it may not have a base domain.
|
||||
pub(crate) fn remove_get_params(url: &str) -> String {
|
||||
pub(crate) fn remove_get_params(url: &str) -> &str {
|
||||
let path = match url.split_once('?') {
|
||||
Some((path, _params)) => path,
|
||||
None => url,
|
||||
};
|
||||
path.to_string()
|
||||
path
|
||||
}
|
||||
|
||||
/// Determine if an element's attribute contains a link / URL.
|
||||
|
|
@ -43,26 +43,17 @@ mod test_fs_tree {
|
|||
|
||||
#[test]
|
||||
fn test_remove_get_params() {
|
||||
assert_eq!(remove_get_params("/"), "/".to_string());
|
||||
assert_eq!(
|
||||
remove_get_params("index.html?foo=bar"),
|
||||
"index.html".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
remove_get_params("/index.html?foo=bar"),
|
||||
"/index.html".to_string()
|
||||
);
|
||||
assert_eq!(remove_get_params("/"), "/");
|
||||
assert_eq!(remove_get_params("index.html?foo=bar"), "index.html");
|
||||
assert_eq!(remove_get_params("/index.html?foo=bar"), "/index.html");
|
||||
assert_eq!(
|
||||
remove_get_params("/index.html?foo=bar&baz=zorx?bla=blub"),
|
||||
"/index.html".to_string()
|
||||
"/index.html"
|
||||
);
|
||||
assert_eq!(
|
||||
remove_get_params("https://example.org/index.html?foo=bar"),
|
||||
"https://example.org/index.html".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
remove_get_params("test.png?foo=bar"),
|
||||
"test.png".to_string()
|
||||
"https://example.org/index.html"
|
||||
);
|
||||
assert_eq!(remove_get_params("test.png?foo=bar"), "test.png");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue