@@ -219,6 +219,9 @@ pub struct ParseOptions<'a> {
219
219
220
220
impl < ' a > ParseOptions < ' a > {
221
221
/// Change the base URL
222
+ ///
223
+ /// See the notes of [`Url::join`] for more details about how this base is considered
224
+ /// when parsing.
222
225
pub fn base_url ( mut self , new : Option < & ' a Url > ) -> Self {
223
226
self . base_url = new;
224
227
self
@@ -370,24 +373,42 @@ impl Url {
370
373
///
371
374
/// The inverse of this is [`make_relative`].
372
375
///
373
- /// Note: a trailing slash is significant.
376
+ /// # Notes
377
+ ///
378
+ /// - A trailing slash is significant.
374
379
/// Without it, the last path component is considered to be a “file” name
375
- /// to be removed to get at the “directory” that is used as the base:
380
+ /// to be removed to get at the “directory” that is used as the base.
381
+ /// - A [scheme relative special URL](https://url.spec.whatwg.org/#scheme-relative-special-url-string)
382
+ /// as input replaces everything in the base URL after the scheme.
383
+ /// - An absolute URL (with a scheme) as input replaces the whole base URL (even the scheme).
376
384
///
377
385
/// # Examples
378
386
///
379
387
/// ```rust
380
388
/// use url::Url;
381
389
/// # use url::ParseError;
382
390
///
391
+ /// // Base without a trailing slash
383
392
/// # fn run() -> Result<(), ParseError> {
384
393
/// let base = Url::parse("https://example.net/a/b.html")?;
385
394
/// let url = base.join("c.png")?;
386
395
/// assert_eq!(url.as_str(), "https://example.net/a/c.png"); // Not /a/b.html/c.png
387
396
///
397
+ /// // Base with a trailing slash
388
398
/// let base = Url::parse("https://example.net/a/b/")?;
389
399
/// let url = base.join("c.png")?;
390
400
/// assert_eq!(url.as_str(), "https://example.net/a/b/c.png");
401
+ ///
402
+ /// // Input as scheme relative special URL
403
+ /// let base = Url::parse("https://alice.com/a")?;
404
+ /// let url = base.join("//eve.com/b")?;
405
+ /// assert_eq!(url.as_str(), "https://eve.com/b");
406
+ ///
407
+ /// // Input as absolute URL
408
+ /// let base = Url::parse("https://alice.com/a")?;
409
+ /// let url = base.join("http://eve.com/b")?;
410
+ /// assert_eq!(url.as_str(), "http://eve.com/b"); // http instead of https
411
+
391
412
/// # Ok(())
392
413
/// # }
393
414
/// # run().unwrap();
0 commit comments