sanitize

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sanitize cleans user-controlled strings before they're written to a terminal or log line, so untrusted input can't forge log lines (CR / LF), smuggle ANSI escape sequences (ESC), spoof text direction (U+202E "Trojan Source" bidi overrides), or hide content (zero-width joiners and other Unicode formatting characters).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Message

func Message(s string) string

Message drops non-printable runes from s. Tabs are preserved since they're commonly used for column alignment.

"Non-printable" follows unicode.IsPrint, which excludes the C0/C1 control sets (0x00-0x1F, 0x7F-0x9F), the Cf "format" category (bidi controls, ZWJ, ZWNJ, BOM, etc.), and the rest of the Cc/Cn/Co/Cs categories. ASCII letters, digits, punctuation, symbols, accented characters, CJK, emoji, and the like all pass through.

Used by console and pretty (the terminal renderers) and by integrations like loghttp before writing user-controlled values. Structured/JSON renderers don't need this because encoding/json escapes control characters automatically.

Types

This section is empty.

Jump to

Keyboard shortcuts

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