Repository: servo/rust-url
Pull request #865 (2023-08-28 09:04:00)

Fix panic in set_path for file URLs 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo) Report
Patch coverage: **`100.00%`** and project coverage change: **`+0.31%`** :tada:
> Comparison is base [(`1158370`)](https://app.codecov.io/gh/servo/rust-url/commit/115837002b4b56be70e3a67813716931c6c88e47?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo) 81.42% compared to head [(`e9b761b`)](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo) 81.74%.
> Report is 1 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master     #865      +/-   ##
==========================================
+ Coverage   81.42%   81.74%   +0.31%     
==========================================
  Files          20       20              
  Lines        3516     3517       +1     
==========================================
+ Hits         2863     2875      +12     
+ Misses        653      642      -11     
```


| [Files Changed](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo) | Coverage Δ | |
|---|---|---|
| [url/src/lib.rs](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo#diff-dXJsL3NyYy9saWIucnM=) | `75.53% <ø> (+1.46%)` | :arrow_up: |
| [idna/src/uts46.rs](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo#diff-aWRuYS9zcmMvdXRzNDYucnM=) | `94.19% <100.00%> (ø)` | |
| [url/src/parser.rs](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo#diff-dXJsL3NyYy9wYXJzZXIucnM=) | `81.49% <100.00%> (+0.02%)` | :arrow_up: |


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/servo/rust-url/pull/865?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=servo).


Patch:
diff --git a/url/Cargo.toml b/url/Cargo.toml
index a9dfa16..969706d 100644
--- a/url/Cargo.toml
+++ b/url/Cargo.toml
@@ -2,7 +2,7 @@
 
 name = "url"
 # When updating version, also modify html_root_url in the lib.rs
-version = "2.4.0"
+version = "2.4.1"
 authors = ["The rust-url developers"]
 
 description = "URL library for Rust, based on the WHATWG URL Standard"
diff --git a/url/src/lib.rs b/url/src/lib.rs
index 3f2788c..58c7c07 100644
--- a/url/src/lib.rs
+++ b/url/src/lib.rs
@@ -134,7 +134,7 @@ url = { version = "2", features = ["debugger_visualizer"] }
 
 */
 
-#![doc(html_root_url = "https://docs.rs/url/2.4.0")]
+#![doc(html_root_url = "https://docs.rs/url/2.4.1")]
 #![cfg_attr(
     feature = "debugger_visualizer",
     debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
diff --git a/url/src/parser.rs b/url/src/parser.rs
index d5ae831..7d94d1d 100644
--- a/url/src/parser.rs
+++ b/url/src/parser.rs
@@ -1202,6 +1202,7 @@ impl<'a> Parser<'a> {
                     _ => {
                         self.check_url_code_point(c, &input);
                         if scheme_type.is_file()
+                            && self.serialization.len() > path_start
                             && is_normalized_windows_drive_letter(
                                 &self.serialization[path_start + 1..],
                             )


Test patch:
diff --git a/url/tests/unit.rs b/url/tests/unit.rs
index 6cb0f37..c27f237 100644
--- a/url/tests/unit.rs
+++ b/url/tests/unit.rs
@@ -472,7 +472,7 @@ fn append_trailing_slash() {
 fn extend_query_pairs_then_mutate() {
     let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap();
     url.query_pairs_mut()
-        .extend_pairs(vec![("auth", "my-token")].into_iter());
+        .extend_pairs(vec![("auth", "my-token")]);
     url.check_invariants().unwrap();
     assert_eq!(
         url.to_string(),
@@ -1298,3 +1298,11 @@ fn test_file_with_drive_and_path() {
     let url2 = url::Url::join(&url, s2).unwrap();
     assert_eq!(url2.to_string(), "file:///p:/a");
 }
+
+#[test]
+fn issue_864() {
+    let mut url = url::Url::parse("file://").unwrap();
+    dbg!(&url);
+    url.set_path("x");
+    dbg!(&url);
+}