Skip to content

Commit

Permalink
fixup! Normalize URL paths: convert /.//p, /..//p, and //p to p
Browse files Browse the repository at this point in the history
  • Loading branch information
theskim committed Dec 16, 2024
1 parent 3ab2945 commit 4fd25f4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,3 +1422,39 @@ fn test_can_be_a_base_with_path_segments_mut() {
.collect();
assert_eq!(segments, vec!["", "not-a-host"]);
}

#[test]
fn test_fuzzing_uri_failures() {
use url::quirks;
let mut url = Url::parse("data:/.dummy.path").unwrap();
assert!(!url.cannot_be_a_base());

url.set_path(".dummy.path");
assert_eq!(url.as_str(), "data:/.dummy.path");
assert_eq!(url.path(), "/.dummy.path");

url.path_segments_mut()
.expect("should have path segments")
.push(".another.dummy.path");
assert_eq!(url.as_str(), "data:/.dummy.path/.another.dummy.path");
assert_eq!(url.path(), "/.dummy.path/.another.dummy.path");

url = Url::parse("web+demo:/").unwrap();
assert!(!url.cannot_be_a_base());

url.set_path("//.dummy.path");
assert_eq!(url.path(), "//.dummy.path");

let segments: Vec<_> = url
.path_segments()
.expect("should have path segments")
.collect();

assert_eq!(segments, vec!["", ".dummy.path"]);

assert_eq!(url.as_str(), "web+demo:/.//.dummy.path");
quirks::set_hostname(&mut url, ".dummy.host").unwrap();
assert_eq!(url.as_str(), "web+demo://.dummy.host//.dummy.path");
quirks::set_hostname(&mut url, "").unwrap();
assert_eq!(url.as_str(), "web+demo:////.dummy.path");
}

0 comments on commit 4fd25f4

Please sign in to comment.