mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-21 05:31:01 +00:00
Revert refactor for removing params and fragments
The refactored version was not equivalent. It could not handle
fragments containing a question mark.
See 67268ed598 (r703400238)
This commit is contained in:
parent
67268ed598
commit
ffab0343fc
1 changed files with 14 additions and 5 deletions
|
|
@ -3,12 +3,13 @@ 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_and_fragment(url: &str) -> &str {
|
||||
let path = match url.split_once('?') {
|
||||
let path = match url.split_once('#') {
|
||||
Some((path_without_fragment, _fragment)) => path_without_fragment,
|
||||
None => url,
|
||||
};
|
||||
let path = match path.split_once('?') {
|
||||
Some((path_without_params, _params)) => path_without_params,
|
||||
None => match url.split_once('#') {
|
||||
Some((path_without_fragment, _fragment)) => path_without_fragment,
|
||||
None => url,
|
||||
},
|
||||
None => path,
|
||||
};
|
||||
path
|
||||
}
|
||||
|
|
@ -80,5 +81,13 @@ mod test_fs_tree {
|
|||
remove_get_params_and_fragment("test.png?foo=bar#anchor"),
|
||||
"test.png"
|
||||
);
|
||||
assert_eq!(
|
||||
remove_get_params_and_fragment("test.png#anchor?anchor!?"),
|
||||
"test.png"
|
||||
);
|
||||
assert_eq!(
|
||||
remove_get_params_and_fragment("test.png?foo=bar#anchor?anchor!"),
|
||||
"test.png"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue