Przeglądaj źródła

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

David Sherret 4 lat temu
rodzic
commit
aee91c171e
2 zmienionych plików z 11 dodań i 1 usunięć
  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 {