Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMaxRunes applies to text sanitization. It defines a default number of runes to truncate a string to if no value is given. DefaultMaxRunes = 300 // DefaultEscapePasses defines a max number of passes to attempt to unescape a string before giving up. DefaultEscapePasses = 5 )
Variables ¶
var AllowedURLSchemes = []string{"http", "https", "ftp", "mailto"}
var ErrInvalid = errors.New("object is invalid")
var ErrNilObject = errors.New("object is nil")
var Validate *validator.Validate
Functions ¶
func IsValid ¶
IsValid will check if an object is valid according to the validation tags on the object. It does not return any details of validation issues, only a boolean for valid (true) or invalid (false).
func ParseStructValidationErrors ¶
ParseStructValidationErrors takes the underlying validation errors and formats them so that each struct field has an array of all validation errors associated with it.
func SanitizeHTML ¶
SanitizeHTML sanitizes strings containing HTML. It performs:
bluemonday -> html unescaping -> trimspace
The resulting string should still contain valid HTML, but will be much safer to use.
func SanitizeInput ¶
SanitizeInput wraps SanitizeText with the DefaultMaxRunes. It should be able to sanitize most inputs that are short-form text.
func SanitizeText ¶
SanitizeText prepares a plain-text field:
strips control bidi-override and zero-width characters -> replaces newlines -> and caps the length.
Output is still untrusted and must be escaped.
func SanitizeURLString ¶
SanitizeURLString attempts to "sanitize" a string value representing a URL. It performs:
path unescaping -> url parsing -> scheme validation
It does not perform other validation, such as checking for absolute vs relative, host, etc.