Function iri_string::validate::absolute_iri [−][src]
Expand description
Validates absolute IRI.
This validator corresponds to RiAbsoluteStr
and RiAbsoluteString
types.
Examples
This type can have an absolute IRI without fragment part.
use iri_string::{spec::UriSpec, validate::absolute_iri};
assert!(absolute_iri::<UriSpec>("https://example.com/foo?bar=baz").is_ok());
assert!(absolute_iri::<UriSpec>("foo:bar").is_ok());
// Scheme `foo` and empty path.
assert!(absolute_iri::<UriSpec>("foo:").is_ok());
// `foo://.../` below are all allowed. See the crate documentation for detail.
assert!(absolute_iri::<UriSpec>("foo:/").is_ok());
assert!(absolute_iri::<UriSpec>("foo://").is_ok());
assert!(absolute_iri::<UriSpec>("foo:///").is_ok());
assert!(absolute_iri::<UriSpec>("foo:////").is_ok());
assert!(absolute_iri::<UriSpec>("foo://///").is_ok());
Relative IRI is not allowed.
use iri_string::{spec::UriSpec, validate::absolute_iri};
// This is relative path.
assert!(absolute_iri::<UriSpec>("foo/bar").is_err());
// `/foo/bar` is an absolute path, but it is authority-relative.
assert!(absolute_iri::<UriSpec>("/foo/bar").is_err());
// `//foo/bar` is termed "network-path reference",
// or usually called "protocol-relative reference".
assert!(absolute_iri::<UriSpec>("//foo/bar").is_err());
// Empty string is not a valid absolute IRI.
assert!(absolute_iri::<UriSpec>("").is_err());
Fragment part (such as trailing #foo
) is not allowed.
use iri_string::{spec::UriSpec, validate::absolute_iri};
// Fragment part is not allowed.
assert!(absolute_iri::<UriSpec>("https://example.com/foo?bar=baz#qux").is_err());
Some characters and sequences cannot used in an absolute IRI.
use iri_string::{spec::UriSpec, validate::absolute_iri};
// `<` and `>` cannot directly appear in an absolute IRI.
assert!(absolute_iri::<UriSpec>("<not allowed>").is_err());
// Broken percent encoding cannot appear in an absolute IRI.
assert!(absolute_iri::<UriSpec>("%").is_err());
assert!(absolute_iri::<UriSpec>("%GG").is_err());