makesafe

package
v0.0.0-...-412af48 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown indicates we don't know if it is safe.
	Unknown protection = iota
	// None requires no special escaping.
	None // Nothing special
	// SingleQuote is unsafe in bash and requires a single quote.
	SingleQuote // Requires at least a single quote
	// DoubleQuote is unsafe in bash and requires escaping or other double-quote features.
	DoubleQuote // Can only be in a double-quoted string
)
View Source
const (
	// IsAQuote is either a `'` or `"`
	IsAQuote = None
	// IsSpace is ascii 32
	IsSpace = SingleQuote
	// ShellUnsafe is ()!$ or other bash special char
	ShellUnsafe = SingleQuote
	// GlobUnsafe means could be a glob char (* or ?)
	GlobUnsafe = SingleQuote
	// InterpolationUnsafe used in bash string interpolation ($)
	InterpolationUnsafe = SingleQuote
	// HasBackslash things like \n \t \r \000 \xFF
	HasBackslash = DoubleQuote
)

Variables

This section is empty.

Functions

func FirstFew

func FirstFew(sl []string) string

FirstFew returns the first few names. If any are truncated, it is noted by appending "...". The exact definition of "few" may change over time, and may be based on the number of chars not the list

func FirstFewFlag

func FirstFewFlag(sl []string) (string, bool)

FirstFewFlag is like FirstFew but returns true if truncation done.

func Redact

func Redact(tainted string) string

Redact returns a string that can be used in a shell single-quoted string. It may not be an exact representation, but it is safe to include on a command line.

Redacted chars are changed to "X". If anything is redacted, the string is surrounded by double quotes ("air quotes") and the string "(redacted)" is added to the end. If nothing is redacted, but it contains spaces, it is surrounded by double quotes.

Example: `s` -> `s` Example: `space cadet.txt` -> `"space cadet.txt"` Example: `drink a \t soda` -> `"drink a X soda"(redacted)` Example: `smile☺` -> `"smile☺`

func RedactMany

func RedactMany(items []string) []string

RedactMany returns the list after processing each element with Redact().

func Shell

func Shell(tainted string) string

Shell returns the string formatted so that it is safe to be pasted into a command line to produce the desired filename as an argument to the command.

func ShellMany

func ShellMany(items []string) []string

ShellMany returns the list after processing each element with Shell().

Types

This section is empty.

Jump to

Keyboard shortcuts

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