Skip to main content

Module util

Module util 

Source
Expand description

Small string helpers without external dependencies.

Functionsยง

content_disposition
Content-Disposition value that forces a download and keeps non-ASCII file names intact (RFC 6266 / RFC 5987).
csv_field
Escapes a CSV field (RFC 4180). Fields starting with characters that spreadsheet programs interpret as formulas are prefixed with '.
format_bytes
Human readable byte size (binary units).
format_number
Formats a number with up to decimals decimals, trimming trailing zeros.
pct_encode
Percent-encodes everything except RFC 3986 unreserved characters.
safe_redirect_target
Only accept local, absolute paths as redirect targets (prevents open redirects via ?next=https://evil.example).
sanitize_filename
Reduces an uploaded file name to a safe base name.