sanitize

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaNumeric

func AlphaNumeric(input string) string

AlphaNumeric removes all non-alphanumeric characters.

Example:

safe := sanitize.AlphaNumeric("user-123!@#")
// Returns: "user123"

func HTML

func HTML(input string) string

HTML escapes HTML special characters to prevent XSS attacks.

Example:

safe := sanitize.HTML("<script>alert('xss')</script>")
// Returns: "&lt;script&gt;alert(&#39;xss&#39;)&lt;/script&gt;"

func IsEmail

func IsEmail(email string) bool

IsEmail validates if a string is a valid email format.

Example:

valid := sanitize.IsEmail("user@example.com") // true
valid := sanitize.IsEmail("invalid-email")    // false

func IsURL

func IsURL(urlStr string) bool

IsURL validates if a string is a valid URL format.

Example:

valid := sanitize.IsURL("https://example.com") // true
valid := sanitize.IsURL("not-a-url")           // false

func Path

func Path(input string) string

Path sanitizes file paths to prevent directory traversal attacks. Removes leading slashes and checks for attempts to escape the base directory.

Example:

safe := sanitize.Path("../../etc/passwd")
// Returns: "etc/passwd"

func StripTags

func StripTags(input string) string

StripTags removes all HTML/XML tags from a string.

Example:

clean := sanitize.StripTags("<p>Hello <b>World</b></p>")
// Returns: "Hello World"

func Truncate

func Truncate(input string, length int) string

Truncate truncates a string to the specified length, adding "..." if truncated.

Example:

short := sanitize.Truncate("This is a long string", 10)
// Returns: "This is a..."

func URL

func URL(input string) string

URL encodes a string for safe use in URLs.

Example:

safe := sanitize.URL("hello world & foo=bar")
// Returns: "hello+world+%26+foo%3Dbar"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL