escape

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package escape includes helpers for escaping and unescaping strings.

Index

Constants

View Source
const NonUTF8String = "\xbd\xb2"

NonUTF8String is a string for which utf8.ValidString returns false.

Variables

View Source
var WeirdStrings = map[string]string{
	"fwdslashes":          "foo/bar/baz",
	"repeatedfwdslashes":  "foo//bar///baz",
	"dotdotslash":         "../foo/../bar/../../baz../",
	"backslashes":         "foo\\bar\\baz",
	"repeatedbackslashes": "..\\foo\\\\bar\\\\\\baz",
	"dotdotbackslash":     "..\\foo\\..\\bar\\..\\..\\baz..\\",
	"quote":               "foo\"bar\"baz",
	"spaces":              "foo bar baz",
	"startwithdigit":      "12345",
	"unicode":             strings.Repeat("☺", 3),

	"ascii-1": makeASCIIString(0, 16),
	"ascii-2": makeASCIIString(16, 32),
	"ascii-3": makeASCIIString(32, 48),
	"ascii-4": makeASCIIString(48, 64),
	"ascii-5": makeASCIIString(64, 80),
	"ascii-6": makeASCIIString(80, 96),
	"ascii-7": makeASCIIString(96, 112),
	"ascii-8": makeASCIIString(112, 128),
}

WeirdStrings are unusual/weird strings for use in testing escaping. The keys are descriptive strings, the values are the weird strings.

Functions

func FooBar123 added in v0.43.0

func FooBar123()

func HexEscape

func HexEscape(s string, shouldEscape func(s []rune, i int) bool) string

HexEscape returns s, with all runes for which shouldEscape returns true escaped to "__0xXXX__", where XXX is the hex representation of the rune value. For example, " " would escape to "__0x20__".

Non-UTF-8 strings will have their non-UTF-8 characters escaped to unicode.ReplacementChar; the original value is lost. Please file an issue if you need non-UTF8 support.

Note: shouldEscape takes the whole string as a slice of runes and an index. Passing it a single byte or a single rune doesn't provide enough context for some escape decisions; for example, the caller might want to escape the second "/" in "//" but not the first one. We pass a slice of runes instead of the string or a slice of bytes because some decisions will be made on a rune basis (e.g., encode all non-ASCII runes).

func HexUnescape

func HexUnescape(s string) string

HexUnescape reverses HexEscape.

func IsASCIIAlphanumeric

func IsASCIIAlphanumeric(r rune) bool

IsASCIIAlphanumeric returns true iff r is alphanumeric: a-z, A-Z, 0-9.

func URLEscape

func URLEscape(s string) string

URLEscape uses url.PathEscape to escape s.

func URLUnescape

func URLUnescape(s string) string

URLUnescape reverses URLEscape using url.PathUnescape. If the unescape returns an error, it returns s.

Types

This section is empty.

Jump to

Keyboard shortcuts

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