pub fn iri_reference<S: Spec>(s: &str) -> Result<(), Error>
Expand description
Validates IRI reference.
This validator corresponds to RiReferenceStr
and RiReferenceString
types.
ยงExamples
This type can have an IRI reference (which can be absolute or relative).
use iri_string::{spec::UriSpec, validate::iri_reference};
assert!(iri_reference::<UriSpec>("https://user:pass@example.com:8080").is_ok());
assert!(iri_reference::<UriSpec>("https://example.com/").is_ok());
assert!(iri_reference::<UriSpec>("https://example.com/foo?bar=baz").is_ok());
assert!(iri_reference::<UriSpec>("https://example.com/foo?bar=baz#qux").is_ok());
assert!(iri_reference::<UriSpec>("foo:bar").is_ok());
assert!(iri_reference::<UriSpec>("foo:").is_ok());
// `foo://.../` below are all allowed. See the crate documentation for detail.
assert!(iri_reference::<UriSpec>("foo:/").is_ok());
assert!(iri_reference::<UriSpec>("foo://").is_ok());
assert!(iri_reference::<UriSpec>("foo:///").is_ok());
assert!(iri_reference::<UriSpec>("foo:////").is_ok());
assert!(iri_reference::<UriSpec>("foo://///").is_ok());
assert!(iri_reference::<UriSpec>("foo/bar").is_ok());
assert!(iri_reference::<UriSpec>("/foo/bar").is_ok());
assert!(iri_reference::<UriSpec>("//foo/bar").is_ok());
assert!(iri_reference::<UriSpec>("#foo").is_ok());
Some characters and sequences cannot used in an IRI reference.
use iri_string::{spec::UriSpec, validate::iri_reference};
// `<` and `>` cannot directly appear in an IRI reference.
assert!(iri_reference::<UriSpec>("<not allowed>").is_err());
// Broken percent encoding cannot appear in an IRI reference.
assert!(iri_reference::<UriSpec>("%").is_err());
assert!(iri_reference::<UriSpec>("%GG").is_err());