struct Components::SafeSrcSet

Overview

srcset is a comma-separated list of "<url> <descriptor>?" candidates โ€” a URL list with descriptors, not a single URL โ€” so SafeURL alone cannot validate it (proposal ยง3.3 external-examiner caveat: "srcset ... needs its own parser, not plain SafeURL").

This parses each candidate, validates its URL component through SafeURL, and validates its descriptor against the width (NNNw) or pixel-density (N.Nx) grammar. The whole value is rejected if ANY candidate is unsafe or malformed โ€” fail closed, not "escape what we can."

Defined in:

components/safe/safe_srcset.cr

Constant Summary

DESCRIPTOR_PATTERN = /\A\d+(\.\d+)?[wx]\z/

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.parse!(srcset : String) : SafeSrcSet #

[View source]

Class Method Detail

def self.parse(srcset : String) : SafeSrcSet | Nil #

[View source]

Instance Method Detail

def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]
def to_s : String #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]