Boundary validator for untrusted decoded JSON maps, command envelopes, and HTTP parameters.
Never calls String.to_atom/1 on external input. Field specs define the exact
permitted keys and types; keys are read by Atom.to_string(key) with fallback
to existing atom keys for internal callers.
Summary
Functions
Normalizes a session title: converts nil or blank strings to nil,
collapses CR/LF/tabs to spaces, trims whitespace, and rejects NUL bytes,
control characters, or titles exceeding 200 characters.
Parses a positive integer from either an integer (> 0) or a base-10 digit string.
Validates an untrusted map against field_specs.
Validates a session ID against ^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$
to prevent path traversal in session directories.
Types
@type field_spec() :: {atom(), field_type()} | {atom(), field_type(), keyword()}
@type field_type() :: :string | :non_empty_string | :id_string | :session_id | :session_tags | :abs_path | :boolean | :int | {:int, keyword()} | :pos_int | {:literal, term()} | {:enum, [term()]} | :map | {:map, [field_spec()]} | {:list, field_type()} | :any
Functions
Normalizes a session title: converts nil or blank strings to nil,
collapses CR/LF/tabs to spaces, trims whitespace, and rejects NUL bytes,
control characters, or titles exceeding 200 characters.
@spec parse_pos_int(term()) :: {:ok, pos_integer()} | {:error, String.t()}
Parses a positive integer from either an integer (> 0) or a base-10 digit string.
@spec validate_map(term(), [field_spec()]) :: {:ok, map()} | {:error, String.t()}
Validates an untrusted map against field_specs.
Each spec is {field_key, type} or {field_key, type, opts} where opts
supports :required, :default, and :nullable. Unknown keys in input
are ignored and omitted from the returned atom-keyed map.
Validates a session ID against ^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$
to prevent path traversal in session directories.