Function iri_string::validate::relative_ref [−][src]
Expand description
Validates relative reference.
This validator corresponds to RiRelativeStr
and RiRelativeString
types.
Valid values
This type can have a relative IRI reference.
use iri_string::{spec::UriSpec, validate::relative_ref};
assert!(relative_ref::<UriSpec>("foo").is_ok());
assert!(relative_ref::<UriSpec>("foo/bar").is_ok());
assert!(relative_ref::<UriSpec>("/foo").is_ok());
assert!(relative_ref::<UriSpec>("//foo/bar").is_ok());
assert!(relative_ref::<UriSpec>("?foo").is_ok());
assert!(relative_ref::<UriSpec>("#foo").is_ok());
assert!(relative_ref::<UriSpec>("foo/bar?baz#qux").is_ok());
// The first path component can have colon if the path is absolute.
assert!(relative_ref::<UriSpec>("/foo:bar/").is_ok());
// Second or following path components can have colon.
assert!(relative_ref::<UriSpec>("foo/bar://baz/").is_ok());
assert!(relative_ref::<UriSpec>("./foo://bar").is_ok());
Absolute form of a reference is not allowed.
use iri_string::{spec::UriSpec, validate::relative_ref};
assert!(relative_ref::<UriSpec>("https://example.com/").is_err());
// The first path component cannot have colon, if the path is not absolute.
assert!(relative_ref::<UriSpec>("foo:bar").is_err());
assert!(relative_ref::<UriSpec>("foo:").is_err());
assert!(relative_ref::<UriSpec>("foo:/").is_err());
assert!(relative_ref::<UriSpec>("foo://").is_err());
assert!(relative_ref::<UriSpec>("foo:///").is_err());
assert!(relative_ref::<UriSpec>("foo:////").is_err());
assert!(relative_ref::<UriSpec>("foo://///").is_err());
Some characters and sequences cannot used in an IRI reference.
use iri_string::{spec::UriSpec, validate::relative_ref};
// `<` and `>` cannot directly appear in a relative IRI reference.
assert!(relative_ref::<UriSpec>("<not allowed>").is_err());
// Broken percent encoding cannot appear in a relative IRI reference.
assert!(relative_ref::<UriSpec>("%").is_err());
assert!(relative_ref::<UriSpec>("%GG").is_err());