diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:13:23 +0000 |
commit | 20431706a863f92cb37dc512fef6e48d192aaf2c (patch) | |
tree | 2867f13f5fd5437ba628c67d7f87309ccadcd286 /vendor/url/src/quirks.rs | |
parent | Releasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/url/src/quirks.rs')
-rw-r--r-- | vendor/url/src/quirks.rs | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/vendor/url/src/quirks.rs b/vendor/url/src/quirks.rs index 0dbc6eb44..0674ebb62 100644 --- a/vendor/url/src/quirks.rs +++ b/vendor/url/src/quirks.rs @@ -14,6 +14,49 @@ use crate::parser::{default_port, Context, Input, Parser, SchemeType}; use crate::{Host, ParseError, Position, Url}; +/// Internal components / offsets of a URL. +/// +/// https://user@pass:example.com:1234/foo/bar?baz#quux +/// | | | | ^^^^| | | +/// | | | | | | | `----- fragment_start +/// | | | | | | `--------- query_start +/// | | | | | `----------------- path_start +/// | | | | `--------------------- port +/// | | | `----------------------- host_end +/// | | `---------------------------------- host_start +/// | `--------------------------------------- username_end +/// `---------------------------------------------- scheme_end +#[derive(Copy, Clone)] +#[cfg(feature = "expose_internals")] +pub struct InternalComponents { + pub scheme_end: u32, + pub username_end: u32, + pub host_start: u32, + pub host_end: u32, + pub port: Option<u16>, + pub path_start: u32, + pub query_start: Option<u32>, + pub fragment_start: Option<u32>, +} + +/// Internal component / parsed offsets of the URL. +/// +/// This can be useful for implementing efficient serialization +/// for the URL. +#[cfg(feature = "expose_internals")] +pub fn internal_components(url: &Url) -> InternalComponents { + InternalComponents { + scheme_end: url.scheme_end, + username_end: url.username_end, + host_start: url.host_start, + host_end: url.host_end, + port: url.port, + path_start: url.path_start, + query_start: url.query_start, + fragment_start: url.fragment_start, + } +} + /// https://url.spec.whatwg.org/#dom-url-domaintoascii pub fn domain_to_ascii(domain: &str) -> String { match Host::parse(domain) { @@ -138,14 +181,10 @@ pub fn set_host(url: &mut Url, new_host: &str) -> Result<(), ()> { } } // Make sure we won't set an empty host to a url with a username or a port - if host == Host::Domain("".to_string()) { - if !username(&url).is_empty() { - return Err(()); - } else if let Some(Some(_)) = opt_port { - return Err(()); - } else if url.port().is_some() { - return Err(()); - } + if host == Host::Domain("".to_string()) + && (!username(url).is_empty() || matches!(opt_port, Some(Some(_))) || url.port().is_some()) + { + return Err(()); } url.set_host_internal(host, opt_port); Ok(()) @@ -177,10 +216,10 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> { // Empty host on special not file url if SchemeType::from(url.scheme()) == SchemeType::SpecialNotFile // Port with an empty host - ||!port(&url).is_empty() + ||!port(url).is_empty() // Empty host that includes credentials || !url.username().is_empty() - || !url.password().unwrap_or(&"").is_empty() + || !url.password().unwrap_or("").is_empty() { return Err(()); } |