Explorar o código

fix: make_relative was missing filename when filenames were equal in another directory

David Sherret %!s(int64=4) %!d(string=hai) anos
pai
achega
aee91c171e
Modificáronse 2 ficheiros con 11 adicións e 1 borrados
  1. 1 1
      url/src/lib.rs
  2. 10 0
      url/tests/unit.rs

+ 1 - 1
url/src/lib.rs

@@ -470,7 +470,7 @@ impl Url {
         }
 
         // Add the filename if they are not the same
-        if base_filename != url_filename {
+        if !relative.is_empty() || base_filename != url_filename {
             // If the URIs filename is empty this means that it was a directory
             // so we'll have to append a '/'.
             //

+ 10 - 0
url/tests/unit.rs

@@ -1084,6 +1084,16 @@ fn test_make_relative() {
             "http://127.0.0.1:8080/test/video?baz=meh#456",
             "video?baz=meh#456",
         ),
+        (
+            "http://127.0.0.1:8080/file.txt",
+            "http://127.0.0.1:8080/test/file.txt",
+            "test/file.txt",
+        ),
+        (
+            "http://127.0.0.1:8080/not_equal.txt",
+            "http://127.0.0.1:8080/test/file.txt",
+            "test/file.txt",
+        ),
     ];
 
     for (base, uri, relative) in &tests {