Skip to content

Commit aee91c1

Browse files
committed
fix: make_relative was missing filename when filenames were equal in another directory
1 parent 8e3e91d commit aee91c1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

url/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl Url {
470470
}
471471

472472
// Add the filename if they are not the same
473-
if base_filename != url_filename {
473+
if !relative.is_empty() || base_filename != url_filename {
474474
// If the URIs filename is empty this means that it was a directory
475475
// so we'll have to append a '/'.
476476
//

url/tests/unit.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,16 @@ fn test_make_relative() {
10841084
"http://127.0.0.1:8080/test/video?baz=meh#456",
10851085
"video?baz=meh#456",
10861086
),
1087+
(
1088+
"http://127.0.0.1:8080/file.txt",
1089+
"http://127.0.0.1:8080/test/file.txt",
1090+
"test/file.txt",
1091+
),
1092+
(
1093+
"http://127.0.0.1:8080/not_equal.txt",
1094+
"http://127.0.0.1:8080/test/file.txt",
1095+
"test/file.txt",
1096+
),
10871097
];
10881098

10891099
for (base, uri, relative) in &tests {

0 commit comments

Comments
 (0)