sanitize

package
v0.0.0-...-a65c540 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: GPL-3.0, BSD-3-Clause Imports: 8 Imported by: 0

README

sanitize GoDoc Go Report Card CircleCI

Package sanitize provides functions to sanitize html and paths with go (golang).

FUNCTIONS

sanitize.Accents(s string) string

Accents replaces a set of accented characters with ascii equivalents.

sanitize.BaseName(s string) string

BaseName makes a string safe to use in a file name, producing a sanitized basename replacing . or / with -. Unlike Name no attempt is made to normalise text as a path.

sanitize.HTML(s string) string

HTML strips html tags with a very simple parser, replace common entities, and escape < and > in the result. The result is intended to be used as plain text.

sanitize.HTMLAllowing(s string, args...[]string) (string, error)

HTMLAllowing parses html and allow certain tags and attributes from the lists optionally specified by args - args[0] is a list of allowed tags, args[1] is a list of allowed attributes. If either is missing default sets are used.

sanitize.Name(s string) string

Name makes a string safe to use in a file name by first finding the path basename, then replacing non-ascii characters.

sanitize.Path(s string) string

Path makes a string safe to use as an url path.

Changes

Version 1.2

Adjusted HTML function to avoid linter warning Added more tests from https://githubengineering.com/githubs-post-csp-journey/ Chnaged name of license file Added badges and change log to readme

Version 1.1 Fixed type in comments. Merge pull request from Povilas Balzaravicius Pawka

  • replace br tags with newline even when they contain a space

Version 1.0 First release

Documentation

Overview

Package sanitize provides functions for sanitizing text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accents

func Accents(s string) string

Accents replaces a set of accented characters with ascii equivalents.

func BaseName

func BaseName(s string) string

BaseName makes a string safe to use in a file name, producing a sanitized basename replacing . or / with -. No attempt is made to normalise a path or normalise case.

func HTML

func HTML(s string) (output string)

HTML strips html tags, replace common entities, and escapes <>&;'" in the result. Note the returned text may contain entities as it is escaped by HTMLEscapeString, and most entities are not translated.

func HTMLAllowing

func HTMLAllowing(s string, args ...[]string) (string, error)

HTMLAllowing sanitizes html, allowing some tags. Arrays of allowed tags and allowed attributes may optionally be passed as the second and third arguments.

func Name

func Name(s string) string

Name makes a string safe to use in a file name by first finding the path basename, then replacing non-ascii characters.

func Path

func Path(s string) string

Path makes a string safe to use as a URL path, removing accents and replacing separators with -. The path may still start at / and is not intended for use as a file system path without prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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