1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

[Vendor] update go-swagger v0.21.0 -> v0.25.0 (#12670)

* Update go-swagger

* vendor
This commit is contained in:
6543
2020-09-01 16:01:23 +02:00
committed by GitHub
parent 66843f2237
commit 3270e7a443
350 changed files with 26353 additions and 5552 deletions

View File

@@ -86,6 +86,7 @@ func newExtJSONParser(r io.Reader, canonical bool) *extJSONParser {
func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
var t bsontype.Type
var err error
initialState := ejp.s
ejp.advanceState()
switch ejp.s {
@@ -113,12 +114,15 @@ func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
case jpsInvalidState:
err = ejp.err
case jpsSawKey:
if initialState == jpsStartState {
return bsontype.EmbeddedDocument, nil
}
t = wrapperKeyBSONType(ejp.k)
if t == bsontype.JavaScript {
switch t {
case bsontype.JavaScript:
// just saw $code, need to check for $scope at same level
_, err := ejp.readValue(bsontype.JavaScript)
_, err = ejp.readValue(bsontype.JavaScript)
if err != nil {
break
}
@@ -127,6 +131,7 @@ func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
case jpsSawEndObject: // type is TypeJavaScript
case jpsSawComma:
ejp.advanceState()
if ejp.s == jpsSawKey && ejp.k == "$scope" {
t = bsontype.CodeWithScope
} else {
@@ -137,6 +142,8 @@ func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
default:
err = ErrInvalidJSON
}
case bsontype.CodeWithScope:
err = errors.New("invalid extended JSON: code with $scope must contain $code before $scope")
}
}
}

View File

@@ -180,7 +180,13 @@ func (ejv *extJSONValue) parseDBPointer() (ns string, oid primitive.ObjectID, er
return ns, oid, nil
}
const rfc3339Milli = "2006-01-02T15:04:05.999Z07:00"
const (
rfc3339Milli = "2006-01-02T15:04:05.999Z07:00"
)
var (
timeFormats = []string{rfc3339Milli, "2006-01-02T15:04:05.999Z0700"}
)
func (ejv *extJSONValue) parseDateTime() (int64, error) {
switch ejv.t {
@@ -198,7 +204,15 @@ func (ejv *extJSONValue) parseDateTime() (int64, error) {
}
func parseDatetimeString(data string) (int64, error) {
t, err := time.Parse(rfc3339Milli, data)
var t time.Time
var err error
// try acceptable time formats until one matches
for _, format := range timeFormats {
t, err = time.Parse(format, data)
if err == nil {
break
}
}
if err != nil {
return 0, fmt.Errorf("invalid $date value string: %s", data)
}
@@ -416,17 +430,20 @@ func (ejv *extJSONValue) parseTimestamp() (t, i uint32, err error) {
switch val.t {
case bsontype.Int32:
if val.v.(int32) < 0 {
return 0, fmt.Errorf("$timestamp %s number should be uint32: %s", key, string(val.v.(int32)))
value := val.v.(int32)
if value < 0 {
return 0, fmt.Errorf("$timestamp %s number should be uint32: %d", key, value)
}
return uint32(val.v.(int32)), nil
return uint32(value), nil
case bsontype.Int64:
if val.v.(int64) < 0 || uint32(val.v.(int64)) > math.MaxUint32 {
return 0, fmt.Errorf("$timestamp %s number should be uint32: %s", key, string(val.v.(int32)))
value := val.v.(int64)
if value < 0 || value > int64(math.MaxUint32) {
return 0, fmt.Errorf("$timestamp %s number should be uint32: %d", key, value)
}
return uint32(val.v.(int64)), nil
return uint32(value), nil
default:
return 0, fmt.Errorf("$timestamp %s value should be uint32, but instead is %s", key, val.t)
}

View File

@@ -536,7 +536,10 @@ func (ejvw *extJSONValueWriter) WriteUndefined() error {
func (ejvw *extJSONValueWriter) WriteDocumentElement(key string) (ValueWriter, error) {
switch ejvw.stack[ejvw.frame].mode {
case mDocument, mTopLevel, mCodeWithScope:
ejvw.buf = append(ejvw.buf, []byte(fmt.Sprintf(`"%s":`, key))...)
var buf bytes.Buffer
writeStringWithEscapes(key, &buf, ejvw.escapeHTML)
ejvw.buf = append(ejvw.buf, []byte(fmt.Sprintf(`%s:`, buf.String()))...)
ejvw.push(mElement)
default:
return nil, ejvw.invalidTransitionErr(mElement, "WriteDocumentElement", []mode{mDocument, mTopLevel, mCodeWithScope})

View File

@@ -183,7 +183,7 @@ func (js *jsonScanner) scanString() (*jsonToken, error) {
case '\\':
c, err = js.readNextByte()
switch c {
case '"', '\\', '/', '\'':
case '"', '\\', '/':
b.WriteByte(c)
case 'b':
b.WriteByte('\b')

View File

@@ -14,7 +14,6 @@ import (
"io"
"math"
"sync"
"unicode"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/bson/primitive"
@@ -373,7 +372,8 @@ func (vr *valueReader) ReadBinary() (b []byte, btype byte, err error) {
return nil, 0, err
}
if btype == 0x02 {
// Check length in case it is an old binary without a length.
if btype == 0x02 && length > 4 {
length, err = vr.readLength()
if err != nil {
return nil, 0, err
@@ -449,6 +449,9 @@ func (vr *valueReader) ReadCodeWithScope() (code string, dr DocumentReader, err
if err != nil {
return "", nil, err
}
if strLength <= 0 {
return "", nil, fmt.Errorf("invalid string length: %d", strLength)
}
strBytes, err := vr.readBytes(strLength)
if err != nil {
return "", nil, err
@@ -817,14 +820,6 @@ func (vr *valueReader) readString() (string, error) {
start := vr.offset
vr.offset += int64(length)
if length == 2 {
asciiByte := vr.d[start]
if asciiByte > unicode.MaxASCII {
return "", fmt.Errorf("invalid ascii byte")
}
}
return string(vr.d[start : start+int64(length)-1]), nil
}

View File

@@ -56,6 +56,13 @@ func (bvwp *BSONValueWriterPool) Get(w io.Writer) ValueWriter {
return vw
}
// GetAtModeElement retrieves a ValueWriterFlusher from the pool and resets it to use w as the destination.
func (bvwp *BSONValueWriterPool) GetAtModeElement(w io.Writer) ValueWriterFlusher {
vw := bvwp.Get(w).(*valueWriter)
vw.push(mElement)
return vw
}
// Put inserts a ValueWriter into the pool. If the ValueWriter is not a BSON ValueWriter, nothing
// happens and ok will be false.
func (bvwp *BSONValueWriterPool) Put(vw ValueWriter) (ok bool) {
@@ -512,17 +519,8 @@ func (vw *valueWriter) WriteDocumentEnd() error {
}
if vw.stack[vw.frame].mode == mTopLevel {
if vw.w != nil {
if sw, ok := vw.w.(*SliceWriter); ok {
*sw = vw.buf
} else {
_, err = vw.w.Write(vw.buf)
if err != nil {
return err
}
// reset buffer
vw.buf = vw.buf[:0]
}
if err = vw.Flush(); err != nil {
return err
}
}
@@ -537,6 +535,23 @@ func (vw *valueWriter) WriteDocumentEnd() error {
return nil
}
func (vw *valueWriter) Flush() error {
if vw.w == nil {
return nil
}
if sw, ok := vw.w.(*SliceWriter); ok {
*sw = vw.buf
return nil
}
if _, err := vw.w.Write(vw.buf); err != nil {
return err
}
// reset buffer
vw.buf = vw.buf[:0]
return nil
}
func (vw *valueWriter) WriteArrayElement() (ValueWriter, error) {
if vw.stack[vw.frame].mode != mArray {
return nil, vw.invalidTransitionError(mValue, "WriteArrayElement", []mode{mArray})

View File

@@ -55,6 +55,12 @@ type ValueWriter interface {
WriteUndefined() error
}
// ValueWriterFlusher is a superset of ValueWriter that exposes functionality to flush to the underlying buffer.
type ValueWriterFlusher interface {
ValueWriter
Flush() error
}
// BytesWriter is the interface used to write BSON bytes to a ValueWriter.
// This interface is meant to be a superset of ValueWriter, so that types that
// implement ValueWriter may also implement this interface.