pub fn authority<S: Spec>(s: &str) -> Result<(), Error>Expand description
Validates IRI authority.
ยงExamples
use iri_string::{spec::UriSpec, validate::authority};
assert!(authority::<UriSpec>("example.com").is_ok());
assert!(authority::<UriSpec>("subdomain.example.com").is_ok());
assert!(authority::<UriSpec>("no-period").is_ok());
// Though strongly discouraged, this percent-encoded reg-name with
// non-UTF-8 bytes is considered syntactically valid.
assert!(authority::<UriSpec>("non-%99-utf-8").is_ok());
// Empty authority is valid. Remember `file:///` has empty authority.
assert!(authority::<UriSpec>("").is_ok());
assert!(authority::<UriSpec>("127.0.0.1:8080").is_ok());
assert!(authority::<UriSpec>("[::127.0.0.1]:8088").is_ok());
// URI/IRI syntax itself does not have limit on the port number.
assert!(authority::<UriSpec>("[::1]:9999999999").is_ok());
// Syntax for future versions of IP addresses.
assert!(authority::<UriSpec>("[v89ab.1+2,3(4)5&6]").is_ok());
assert!(authority::<UriSpec>("user:password@host").is_ok());
assert!(authority::<UriSpec>("co%3Alon:at%40sign@host:8888").is_ok());
// Percent-encoded non-UTF8 (or even non-ASCII) bytes are valid.
// Users are responsible to validate or reject such unusual input if needed.
assert!(authority::<UriSpec>("not-a-%80-utf8@host").is_ok());
// Invalid percent encodings.
assert!(authority::<UriSpec>("invalid%GGescape@host").is_err());
// Invalid characters.
assert!(authority::<UriSpec>("foo@bar@host").is_err());
assert!(authority::<UriSpec>("slash/is-not-allowed").is_err());