Skip to content

Commit 3de67cc

Browse files
committed
Fix #1123
1 parent 55ff72d commit 3de67cc

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

url/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,13 @@ impl Url {
17591759
/// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
17601760
/// assert_eq!(url.path(), "/api/some%20comments");
17611761
///
1762+
/// // `set_path` will encode leading `/` and trailing ` ` in cannot-be-a-base paths.
1763+
/// let mut url = Url::parse("a: ?")?;
1764+
/// assert_eq!(url.path(), " %20");
1765+
/// url.set_query(None);
1766+
/// url.set_path("/ ");
1767+
/// assert_eq!(url.path(), "%2F %20");
1768+
///
17621769
/// # Ok(())
17631770
/// # }
17641771
/// # run().unwrap();

url/src/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,10 @@ impl Parser<'_> {
14311431
Some(('?', _)) | Some(('#', _)) if self.context == Context::UrlParser => {
14321432
return input_before_c
14331433
}
1434+
Some((' ', _)) if input.starts_with('?') || input.starts_with('#') || input.is_empty() => {
1435+
self.serialization.push_str("%20");
1436+
return input;
1437+
}
14341438
Some((c, utf8_c)) => {
14351439
self.check_url_code_point(c, &input);
14361440
self.serialization

0 commit comments

Comments
 (0)