struct

Ktistec::SafeURI

Inherits Struct < Value < Object

A String wrapper marking a URL safe to emit raw into a URL attribute slot (href, src, action, ...).

from? and from validate input and admit only absolute URLs with an allowlisted display scheme (http, https, mailto, tel, ...).

Constants

EMPTY_URI = assert_safe("")

A trusted empty URI.

Constructors

assert_safe(string : String) : SafeURI

Asserts the input is already a safe URI.

Source
from(string : String) : SafeURI

Validates and wraps the input.

Same admission rules as from? (absolute URL, allowlisted display scheme).

Raises ArgumentError if invalid.

Use when the input is expected to always succeed and a failure indicates a bug worth surfacing.

Source

Class methods

from?(string : String) : SafeURI | Nil

Validates and wraps the input.

Admits an absolute URL with an allowlisted display scheme (http, https, mailto, tel, ...). Rejects relative references.

Returns nil if invalid.

Use when the input is expected to sometimes fail and graceful continuation is preferred.

Source

Instance methods

==(other : SafeURI) : Bool
Source
==(other : String) : Bool
Source
=~(other : Regex)
Source
empty?(*args, **options)
Source
empty?(*args, **options, &)
Source
presence

Returns self if the wrapped value has presence, otherwise nil.

Source
size(*args, **options)
Source
size(*args, **options, &)
Source
to_json(*args, **options)
Source
to_json(*args, **options, &)
Source
to_s(*args, **options)
Source
to_s(*args, **options, &)
Source