Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Safe ¶
Safe creates a sanitised text node from the given content. If the content fails validation, it returns an error text node instead.
func SafeScript ¶
SafeScript creates a sanitised script element with inline JavaScript. If the JavaScript content fails validation, it returns an error comment instead.
Types ¶
type SanitiseBuilder ¶
type SanitiseBuilder struct {
// contains filtered or unexported fields
}
SanitiseBuilder allows fluent validation with error handling
func Sanitise ¶
func Sanitise(comp node.Node) *SanitiseBuilder
Sanitise creates a new validation builder for the given component. It performs security validation checks against potentially unsafe content within the rendered output. This is useful when rendering raw content into <script> or <style> blocks where injection is possible.
Basic usage (renders component if valid, nothing if invalid):
security.Sanitise(scriptComponent)
With error fallback (renders an error message if invalid):
security.Sanitise(scriptComponent).Error()
func (*SanitiseBuilder) DynamicKey ¶ added in v0.2.0
func (sb *SanitiseBuilder) DynamicKey() string
DynamicKey returns an empty string — sanitise builders do not carry tracking keys.
func (*SanitiseBuilder) Error ¶
func (sb *SanitiseBuilder) Error() node.Node
Error returns a fallback component that renders the original component if valid, or an error message component if validation failed
func (*SanitiseBuilder) IsDynamic ¶ added in v0.2.0
func (sb *SanitiseBuilder) IsDynamic() bool
IsDynamic returns true as SanitiseBuilder performs runtime validation.
func (*SanitiseBuilder) Nodes ¶
func (sb *SanitiseBuilder) Nodes() []node.Node
Nodes returns the children of the wrapped component if valid, or an empty slice if validation failed
func (*SanitiseBuilder) Render ¶
func (sb *SanitiseBuilder) Render(w ...io.Writer) []byte
Render renders the original component if valid, or an empty byte slice if invalid
func (*SanitiseBuilder) RenderBuilder ¶
func (sb *SanitiseBuilder) RenderBuilder(buf *bytes.Buffer)
RenderBuilder renders the original component into the given buffer if valid, or writes nothing if validation failed