forked from forgejo/forgejo
Vendor Update Go Libs (#13166)
* update github.com/alecthomas/chroma v0.8.0 -> v0.8.1 * github.com/blevesearch/bleve v1.0.10 -> v1.0.12 * editorconfig-core-go v2.1.1 -> v2.3.7 * github.com/gliderlabs/ssh v0.2.2 -> v0.3.1 * migrate editorconfig.ParseBytes to Parse * github.com/shurcooL/vfsgen to 0d455de96546 * github.com/go-git/go-git/v5 v5.1.0 -> v5.2.0 * github.com/google/uuid v1.1.1 -> v1.1.2 * github.com/huandu/xstrings v1.3.0 -> v1.3.2 * github.com/klauspost/compress v1.10.11 -> v1.11.1 * github.com/markbates/goth v1.61.2 -> v1.65.0 * github.com/mattn/go-sqlite3 v1.14.0 -> v1.14.4 * github.com/mholt/archiver v3.3.0 -> v3.3.2 * github.com/microcosm-cc/bluemonday 4f7140c49acb -> v1.0.4 * github.com/minio/minio-go v7.0.4 -> v7.0.5 * github.com/olivere/elastic v7.0.9 -> v7.0.20 * github.com/urfave/cli v1.20.0 -> v1.22.4 * github.com/prometheus/client_golang v1.1.0 -> v1.8.0 * github.com/xanzy/go-gitlab v0.37.0 -> v0.38.1 * mvdan.cc/xurls v2.1.0 -> v2.2.0 Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
91f2afdb54
commit
12a1f914f4
656 changed files with 52967 additions and 25229 deletions
216
vendor/github.com/mailru/easyjson/jlexer/lexer.go
generated
vendored
216
vendor/github.com/mailru/easyjson/jlexer/lexer.go
generated
vendored
|
@ -5,6 +5,7 @@
|
|||
package jlexer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
@ -14,6 +15,8 @@ import (
|
|||
"unicode"
|
||||
"unicode/utf16"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/josharian/intern"
|
||||
)
|
||||
|
||||
// tokenKind determines type of a token.
|
||||
|
@ -32,9 +35,10 @@ const (
|
|||
type token struct {
|
||||
kind tokenKind // Type of a token.
|
||||
|
||||
boolValue bool // Value if a boolean literal token.
|
||||
byteValue []byte // Raw value of a token.
|
||||
delimValue byte
|
||||
boolValue bool // Value if a boolean literal token.
|
||||
byteValueCloned bool // true if byteValue was allocated and does not refer to original json body
|
||||
byteValue []byte // Raw value of a token.
|
||||
delimValue byte
|
||||
}
|
||||
|
||||
// Lexer is a JSON lexer: it iterates over JSON tokens in a byte slice.
|
||||
|
@ -240,23 +244,65 @@ func (r *Lexer) fetchNumber() {
|
|||
|
||||
// findStringLen tries to scan into the string literal for ending quote char to determine required size.
|
||||
// The size will be exact if no escapes are present and may be inexact if there are escaped chars.
|
||||
func findStringLen(data []byte) (isValid, hasEscapes bool, length int) {
|
||||
delta := 0
|
||||
|
||||
for i := 0; i < len(data); i++ {
|
||||
switch data[i] {
|
||||
case '\\':
|
||||
i++
|
||||
delta++
|
||||
if i < len(data) && data[i] == 'u' {
|
||||
delta++
|
||||
}
|
||||
case '"':
|
||||
return true, (delta > 0), (i - delta)
|
||||
func findStringLen(data []byte) (isValid bool, length int) {
|
||||
for {
|
||||
idx := bytes.IndexByte(data, '"')
|
||||
if idx == -1 {
|
||||
return false, len(data)
|
||||
}
|
||||
if idx == 0 || (idx > 0 && data[idx-1] != '\\') {
|
||||
return true, length + idx
|
||||
}
|
||||
|
||||
// count \\\\\\\ sequences. even number of slashes means quote is not really escaped
|
||||
cnt := 1
|
||||
for idx-cnt-1 >= 0 && data[idx-cnt-1] == '\\' {
|
||||
cnt++
|
||||
}
|
||||
if cnt%2 == 0 {
|
||||
return true, length + idx
|
||||
}
|
||||
|
||||
length += idx + 1
|
||||
data = data[idx+1:]
|
||||
}
|
||||
}
|
||||
|
||||
// unescapeStringToken performs unescaping of string token.
|
||||
// if no escaping is needed, original string is returned, otherwise - a new one allocated
|
||||
func (r *Lexer) unescapeStringToken() (err error) {
|
||||
data := r.token.byteValue
|
||||
var unescapedData []byte
|
||||
|
||||
for {
|
||||
i := bytes.IndexByte(data, '\\')
|
||||
if i == -1 {
|
||||
break
|
||||
}
|
||||
|
||||
escapedRune, escapedBytes, err := decodeEscape(data[i:])
|
||||
if err != nil {
|
||||
r.errParse(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if unescapedData == nil {
|
||||
unescapedData = make([]byte, 0, len(r.token.byteValue))
|
||||
}
|
||||
|
||||
var d [4]byte
|
||||
s := utf8.EncodeRune(d[:], escapedRune)
|
||||
unescapedData = append(unescapedData, data[:i]...)
|
||||
unescapedData = append(unescapedData, d[:s]...)
|
||||
|
||||
data = data[i+escapedBytes:]
|
||||
}
|
||||
|
||||
return false, false, len(data)
|
||||
if unescapedData != nil {
|
||||
r.token.byteValue = append(unescapedData, data...)
|
||||
r.token.byteValueCloned = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// getu4 decodes \uXXXX from the beginning of s, returning the hex value,
|
||||
|
@ -286,36 +332,30 @@ func getu4(s []byte) rune {
|
|||
return val
|
||||
}
|
||||
|
||||
// processEscape processes a single escape sequence and returns number of bytes processed.
|
||||
func (r *Lexer) processEscape(data []byte) (int, error) {
|
||||
// decodeEscape processes a single escape sequence and returns number of bytes processed.
|
||||
func decodeEscape(data []byte) (decoded rune, bytesProcessed int, err error) {
|
||||
if len(data) < 2 {
|
||||
return 0, fmt.Errorf("syntax error at %v", string(data))
|
||||
return 0, 0, errors.New("incorrect escape symbol \\ at the end of token")
|
||||
}
|
||||
|
||||
c := data[1]
|
||||
switch c {
|
||||
case '"', '/', '\\':
|
||||
r.token.byteValue = append(r.token.byteValue, c)
|
||||
return 2, nil
|
||||
return rune(c), 2, nil
|
||||
case 'b':
|
||||
r.token.byteValue = append(r.token.byteValue, '\b')
|
||||
return 2, nil
|
||||
return '\b', 2, nil
|
||||
case 'f':
|
||||
r.token.byteValue = append(r.token.byteValue, '\f')
|
||||
return 2, nil
|
||||
return '\f', 2, nil
|
||||
case 'n':
|
||||
r.token.byteValue = append(r.token.byteValue, '\n')
|
||||
return 2, nil
|
||||
return '\n', 2, nil
|
||||
case 'r':
|
||||
r.token.byteValue = append(r.token.byteValue, '\r')
|
||||
return 2, nil
|
||||
return '\r', 2, nil
|
||||
case 't':
|
||||
r.token.byteValue = append(r.token.byteValue, '\t')
|
||||
return 2, nil
|
||||
return '\t', 2, nil
|
||||
case 'u':
|
||||
rr := getu4(data)
|
||||
if rr < 0 {
|
||||
return 0, errors.New("syntax error")
|
||||
return 0, 0, errors.New("incorrectly escaped \\uXXXX sequence")
|
||||
}
|
||||
|
||||
read := 6
|
||||
|
@ -328,13 +368,10 @@ func (r *Lexer) processEscape(data []byte) (int, error) {
|
|||
rr = unicode.ReplacementChar
|
||||
}
|
||||
}
|
||||
var d [4]byte
|
||||
s := utf8.EncodeRune(d[:], rr)
|
||||
r.token.byteValue = append(r.token.byteValue, d[:s]...)
|
||||
return read, nil
|
||||
return rr, read, nil
|
||||
}
|
||||
|
||||
return 0, errors.New("syntax error")
|
||||
return 0, 0, errors.New("incorrectly escaped bytes")
|
||||
}
|
||||
|
||||
// fetchString scans a string literal token.
|
||||
|
@ -342,43 +379,14 @@ func (r *Lexer) fetchString() {
|
|||
r.pos++
|
||||
data := r.Data[r.pos:]
|
||||
|
||||
isValid, hasEscapes, length := findStringLen(data)
|
||||
isValid, length := findStringLen(data)
|
||||
if !isValid {
|
||||
r.pos += length
|
||||
r.errParse("unterminated string literal")
|
||||
return
|
||||
}
|
||||
if !hasEscapes {
|
||||
r.token.byteValue = data[:length]
|
||||
r.pos += length + 1
|
||||
return
|
||||
}
|
||||
|
||||
r.token.byteValue = make([]byte, 0, length)
|
||||
p := 0
|
||||
for i := 0; i < len(data); {
|
||||
switch data[i] {
|
||||
case '"':
|
||||
r.pos += i + 1
|
||||
r.token.byteValue = append(r.token.byteValue, data[p:i]...)
|
||||
i++
|
||||
return
|
||||
|
||||
case '\\':
|
||||
r.token.byteValue = append(r.token.byteValue, data[p:i]...)
|
||||
off, err := r.processEscape(data[i:])
|
||||
if err != nil {
|
||||
r.errParse(err.Error())
|
||||
return
|
||||
}
|
||||
i += off
|
||||
p = i
|
||||
|
||||
default:
|
||||
i++
|
||||
}
|
||||
}
|
||||
r.errParse("unterminated string literal")
|
||||
r.token.byteValue = data[:length]
|
||||
r.pos += length + 1 // skip closing '"' as well
|
||||
}
|
||||
|
||||
// scanToken scans the next token if no token is currently available in the lexer.
|
||||
|
@ -602,7 +610,7 @@ func (r *Lexer) Consumed() {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Lexer) unsafeString() (string, []byte) {
|
||||
func (r *Lexer) unsafeString(skipUnescape bool) (string, []byte) {
|
||||
if r.token.kind == tokenUndef && r.Ok() {
|
||||
r.FetchToken()
|
||||
}
|
||||
|
@ -610,6 +618,13 @@ func (r *Lexer) unsafeString() (string, []byte) {
|
|||
r.errInvalidToken("string")
|
||||
return "", nil
|
||||
}
|
||||
if !skipUnescape {
|
||||
if err := r.unescapeStringToken(); err != nil {
|
||||
r.errInvalidToken("string")
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
bytes := r.token.byteValue
|
||||
ret := bytesToStr(r.token.byteValue)
|
||||
r.consume()
|
||||
|
@ -621,13 +636,19 @@ func (r *Lexer) unsafeString() (string, []byte) {
|
|||
// Warning: returned string may point to the input buffer, so the string should not outlive
|
||||
// the input buffer. Intended pattern of usage is as an argument to a switch statement.
|
||||
func (r *Lexer) UnsafeString() string {
|
||||
ret, _ := r.unsafeString()
|
||||
ret, _ := r.unsafeString(false)
|
||||
return ret
|
||||
}
|
||||
|
||||
// UnsafeBytes returns the byte slice if the token is a string literal.
|
||||
func (r *Lexer) UnsafeBytes() []byte {
|
||||
_, ret := r.unsafeString()
|
||||
_, ret := r.unsafeString(false)
|
||||
return ret
|
||||
}
|
||||
|
||||
// UnsafeFieldName returns current member name string token
|
||||
func (r *Lexer) UnsafeFieldName(skipUnescape bool) string {
|
||||
ret, _ := r.unsafeString(skipUnescape)
|
||||
return ret
|
||||
}
|
||||
|
||||
|
@ -640,7 +661,34 @@ func (r *Lexer) String() string {
|
|||
r.errInvalidToken("string")
|
||||
return ""
|
||||
}
|
||||
ret := string(r.token.byteValue)
|
||||
if err := r.unescapeStringToken(); err != nil {
|
||||
r.errInvalidToken("string")
|
||||
return ""
|
||||
}
|
||||
var ret string
|
||||
if r.token.byteValueCloned {
|
||||
ret = bytesToStr(r.token.byteValue)
|
||||
} else {
|
||||
ret = string(r.token.byteValue)
|
||||
}
|
||||
r.consume()
|
||||
return ret
|
||||
}
|
||||
|
||||
// StringIntern reads a string literal, and performs string interning on it.
|
||||
func (r *Lexer) StringIntern() string {
|
||||
if r.token.kind == tokenUndef && r.Ok() {
|
||||
r.FetchToken()
|
||||
}
|
||||
if !r.Ok() || r.token.kind != tokenString {
|
||||
r.errInvalidToken("string")
|
||||
return ""
|
||||
}
|
||||
if err := r.unescapeStringToken(); err != nil {
|
||||
r.errInvalidToken("string")
|
||||
return ""
|
||||
}
|
||||
ret := intern.Bytes(r.token.byteValue)
|
||||
r.consume()
|
||||
return ret
|
||||
}
|
||||
|
@ -839,7 +887,7 @@ func (r *Lexer) Int() int {
|
|||
}
|
||||
|
||||
func (r *Lexer) Uint8Str() uint8 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -856,7 +904,7 @@ func (r *Lexer) Uint8Str() uint8 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Uint16Str() uint16 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -873,7 +921,7 @@ func (r *Lexer) Uint16Str() uint16 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Uint32Str() uint32 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -890,7 +938,7 @@ func (r *Lexer) Uint32Str() uint32 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Uint64Str() uint64 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -915,7 +963,7 @@ func (r *Lexer) UintptrStr() uintptr {
|
|||
}
|
||||
|
||||
func (r *Lexer) Int8Str() int8 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -932,7 +980,7 @@ func (r *Lexer) Int8Str() int8 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Int16Str() int16 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -949,7 +997,7 @@ func (r *Lexer) Int16Str() int16 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Int32Str() int32 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -966,7 +1014,7 @@ func (r *Lexer) Int32Str() int32 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Int64Str() int64 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -1004,7 +1052,7 @@ func (r *Lexer) Float32() float32 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Float32Str() float32 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
@ -1037,7 +1085,7 @@ func (r *Lexer) Float64() float64 {
|
|||
}
|
||||
|
||||
func (r *Lexer) Float64Str() float64 {
|
||||
s, b := r.unsafeString()
|
||||
s, b := r.unsafeString(false)
|
||||
if !r.Ok() {
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue