Documentation ¶
Overview ¶
Package escape includes helpers for escaping and unescaping strings.
Index ¶
Constants ¶
const NonUTF8String = "\xbd\xb2"
NonUTF8String is a string for which utf8.ValidString returns false.
Variables ¶
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 HexEscape ¶
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 IsASCIIAlphanumeric ¶
IsASCIIAlphanumeric returns true iff r is alphanumeric: a-z, A-Z, 0-9.
func URLUnescape ¶
URLUnescape reverses URLEscape using url.PathUnescape. If the unescape returns an error, it returns s.
Types ¶
This section is empty.