File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -1551,6 +1551,19 @@ impl Url {
1551
1551
/// url.set_path("data/report.csv");
1552
1552
/// assert_eq!(url.as_str(), "https://example.com/data/report.csv");
1553
1553
/// assert_eq!(url.path(), "/data/report.csv");
1554
+ ///
1555
+ /// // `set_path` percent-encodes the given string if it's not already percent-encoded.
1556
+ /// let mut url = Url::parse("https://example.com")?;
1557
+ /// url.set_path("api/some comments");
1558
+ /// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
1559
+ /// assert_eq!(url.path(), "/api/some%20comments");
1560
+ ///
1561
+ /// // `set_path` will not double percent-encode the string if it's already percent-encoded.
1562
+ /// let mut url = Url::parse("https://example.com")?;
1563
+ /// url.set_path("api/some%20comments");
1564
+ /// assert_eq!(url.as_str(), "https://example.com/api/some%20comments");
1565
+ /// assert_eq!(url.path(), "/api/some%20comments");
1566
+ ///
1554
1567
/// # Ok(())
1555
1568
/// # }
1556
1569
/// # run().unwrap();
You can’t perform that action at this time.
0 commit comments