Help us shape the future of Go! Take the 2026 Go Developer Survey

sanitize

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sanitize cleans text before it leaves the console: error messages for a client or the audit log (known secrets in every encoded form, then the product's registered patterns), and any text printed for the human (control and bidi characters escaped, so that client-supplied text cannot drive or spoof the terminal).

Index

Constants

This section is empty.

Variables

View Source
var URLUserinfo = regexp.MustCompile(`\b[A-Za-z][A-Za-z0-9+.-]*://([^\s/?#@]+@)`)

URLUserinfo matches the userinfo of a URL ("user:password@" in "amqps://user:password@host"); registered, it drops it. It is not a default: products whose errors carry such URLs register it.

Functions

func Terminal

func Terminal(s string, multiline bool) string

Terminal escapes s for the human's terminal: C0 and C1 controls and DEL as \xNN, bidi and directional marks as \uNNNN, so that client-supplied text cannot drive or spoof the terminal. Newlines and tabs are kept when multiline is set.

Types

type Sanitizer

type Sanitizer struct {
	// contains filtered or unexported fields
}

Sanitizer scrubs error text. The zero value is not usable: call New.

func New

func New(patterns ...*regexp.Regexp) *Sanitizer

New returns a sanitizer with the given patterns registered.

func (*Sanitizer) Clean

func (s *Sanitizer) Clean(text string, known ...[]byte) string

Clean removes every known secret from text, then applies the patterns.

func (*Sanitizer) Error

func (s *Sanitizer) Error(err error, known ...[]byte) string

Error is Clean of err's message; a nil err gives "".

func (*Sanitizer) Register

func (s *Sanitizer) Register(p *regexp.Regexp)

Register adds a pattern. In each match, the text of every capturing group is removed; a pattern without a group has its whole match replaced by secrets.Redacted.

Jump to

Keyboard shortcuts

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