class
Components::SafeBuffer
- Components::SafeBuffer
- Reference
- Object
Overview
SafeBuffer is the construction mechanism paired with SafeHTML the
output contract. It is an accumulator with one load-bearing rule
(proposal §3.2 point 3): appending a String always means text and is
always HTML-escaped. There is no overload that takes a raw String and
treats it as markup — that is exactly the "buffer that's sometimes raw"
design the hardening proposal rejects, because it recreates the hole.
Structure comes from appending SafeHTML / Elements::HTMLElement /
Elements::RawHTML values (already-safe markup, passed through
verbatim), never from interpolating a String that happens to contain
tags — buf << "<b>#{x}</b>" escapes the entire literal, producing a
visible <b>... cosmetic bug the author sees and fixes. That is
the intended failure mode (see docs/SAFE_HTML_V1.md).
Defined in:
components/safe/safe_buffer.crConstructors
Instance Method Summary
-
#<<(text : String) : self
A plain String is TEXT.
-
#<<(safe : SafeHTML) : self
Already-safe markup — passthrough, no re-escaping.
-
#<<(el : Elements::HTMLElement) : self
HTMLElement#renderalready escapes its own text children and attribute values internally (§3.1 of the proposal — this DSL is already safe-by-default), so its serialized form is trusted verbatim. -
#<<(raw_html : Elements::RawHTML) : self
The explicit, existing "I mean it" raw wrapper — passthrough.
- #<<(component : Component) : self
-
#<<(other : Int | Float | Bool | Char) : self
Scalars: escape their
to_sform. - #to_safe_html : SafeHTML
Constructor Detail
Instance Method Detail
A plain String is TEXT. Always escaped. Deliberately the only overload
that accepts String.
HTMLElement#render already escapes its own text children and
attribute values internally (§3.1 of the proposal — this DSL is
already safe-by-default), so its serialized form is trusted verbatim.
The explicit, existing "I mean it" raw wrapper — passthrough.
Scalars: escape their to_s form. Harmless for numbers/bools, and
future-proofs against a scalar type whose to_s could ever contain
markup-shaped characters.