diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-01-29 14:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 14:17:40 -0800 |
commit | 961c04cae992eadb42d286d2f85f8a675bdc68c8 (patch) | |
tree | 3408f2d06f847e966c53485e2d54c692cdd037c1 /vendor/github.com/pelletier/go-toml/keysparsing.go | |
parent | 8d66523ba7d9a77129844be476732ebfd5272d64 (diff) | |
download | chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.gz chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.bz2 chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.zip |
Upgrading server dependancies (#8154)
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/keysparsing.go')
-rw-r--r-- | vendor/github.com/pelletier/go-toml/keysparsing.go | 104 |
1 files changed, 14 insertions, 90 deletions
diff --git a/vendor/github.com/pelletier/go-toml/keysparsing.go b/vendor/github.com/pelletier/go-toml/keysparsing.go index 0da938b03..284db6467 100644 --- a/vendor/github.com/pelletier/go-toml/keysparsing.go +++ b/vendor/github.com/pelletier/go-toml/keysparsing.go @@ -6,36 +6,16 @@ import ( "bytes" "errors" "fmt" - "strconv" "unicode" ) -var escapeSequenceMap = map[rune]rune{ - 'b': '\b', - 't': '\t', - 'n': '\n', - 'f': '\f', - 'r': '\r', - '"': '"', - '\\': '\\', -} - -type parseKeyState int - -const ( - bare parseKeyState = iota - basic - literal - esc - unicode4 - unicode8 -) - +// Convert the bare key group string to an array. +// The input supports double quotation to allow "." inside the key name, +// but escape sequences are not supported. Lexers must unescape them beforehand. func parseKey(key string) ([]string, error) { groups := []string{} var buffer bytes.Buffer - var hex bytes.Buffer - state := bare + inQuotes := false wasInQuotes := false ignoreSpace := true expectDot := false @@ -47,67 +27,17 @@ func parseKey(key string) ([]string, error) { } ignoreSpace = false } - - if state == esc { - if char == 'u' { - state = unicode4 - hex.Reset() - } else if char == 'U' { - state = unicode8 - hex.Reset() - } else if newChar, ok := escapeSequenceMap[char]; ok { - buffer.WriteRune(newChar) - state = basic - } else { - return nil, fmt.Errorf(`invalid escape sequence \%c`, char) - } - continue - } - - if state == unicode4 || state == unicode8 { - if isHexDigit(char) { - hex.WriteRune(char) - } - if (state == unicode4 && hex.Len() == 4) || (state == unicode8 && hex.Len() == 8) { - if value, err := strconv.ParseInt(hex.String(), 16, 32); err == nil { - buffer.WriteRune(rune(value)) - } else { - return nil, err - } - state = basic - } - continue - } - switch char { - case '\\': - if state == basic { - state = esc - } else if state == literal { - buffer.WriteRune(char) - } - case '\'': - if state == bare { - state = literal - } else if state == literal { - groups = append(groups, buffer.String()) - buffer.Reset() - wasInQuotes = true - state = bare - } - expectDot = false case '"': - if state == bare { - state = basic - } else if state == basic { + if inQuotes { groups = append(groups, buffer.String()) buffer.Reset() - state = bare wasInQuotes = true } + inQuotes = !inQuotes expectDot = false case '.': - if state != bare { + if inQuotes { buffer.WriteRune(char) } else { if !wasInQuotes { @@ -122,31 +52,25 @@ func parseKey(key string) ([]string, error) { wasInQuotes = false } case ' ': - if state == basic { + if inQuotes { buffer.WriteRune(char) } else { expectDot = true } default: - if state == bare { - if !isValidBareChar(char) { - return nil, fmt.Errorf("invalid bare character: %c", char) - } else if expectDot { - return nil, errors.New("what?") - } + if !inQuotes && !isValidBareChar(char) { + return nil, fmt.Errorf("invalid bare character: %c", char) + } + if !inQuotes && expectDot { + return nil, errors.New("what?") } buffer.WriteRune(char) expectDot = false } } - - // state must be bare at the end - if state == esc { - return nil, errors.New("unfinished escape sequence") - } else if state != bare { + if inQuotes { return nil, errors.New("mismatched quotes") } - if buffer.Len() > 0 { groups = append(groups, buffer.String()) } |