Skip to content

Commit af54a1d

Browse files
committed
Merge remote-tracking branch 'mongodb/master' into fixed-bson-ec-time
2 parents e777c16 + 3e6d365 commit af54a1d

File tree

236 files changed

+24762
-4787
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+24762
-4787
lines changed

.errcheck-excludes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
(*github.com/mongodb/mongo-go-driver/core/topology.Subscription).Unsubscribe
44
(*github.com/mongodb/mongo-go-driver/core/topology.Server).Close
55
(*github.com/mongodb/mongo-go-driver/core/connection.pool).closeConnection
6+
(github.com/mongodb/mongo-go-driver/core/wiremessage.ReadWriteCloser).Close
67
(net.Conn).Close
78
encoding/pem.Encode
89
fmt.Fprintf

.evergreen/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ tasks:
401401
commands:
402402
- func: bootstrap-mongo-orchestration
403403
vars:
404-
topology: "server"
405-
auth: "auth"
406-
ssl: "ssl"
404+
TOPOLOGY: "server"
405+
AUTH: "auth"
406+
SSL: "ssl"
407407
- func: run-tests
408408
vars:
409-
topology: "server"
410-
auth: "auth"
411-
ssl: "ssl"
409+
TOPOLOGY: "server"
410+
AUTH: "auth"
411+
SSL: "ssl"
412412
MONGO_GO_DRIVER_COMPRESSOR: "snappy"
413413

414414
- name: test-replicaset-noauth-nossl
@@ -585,6 +585,10 @@ axes:
585585
- id: version
586586
display_name: MongoDB Version
587587
values:
588+
- id: "4.0"
589+
display_name: "4.0"
590+
variables:
591+
VERSION: "4.0"
588592
- id: "3.6"
589593
display_name: "3.6"
590594
variables:

THIRD-PARTY-NOTICES

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,32 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6060
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6161
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6262

63+
----------------------------------------------------------------------
64+
License notice for github.com/buger/jsonparser
65+
----------------------------------------------------------------------
66+
67+
MIT License
68+
69+
Copyright (c) 2016 Leonid Bugaev
70+
71+
Permission is hereby granted, free of charge, to any person obtaining a copy
72+
of this software and associated documentation files (the "Software"), to deal
73+
in the Software without restriction, including without limitation the rights
74+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
75+
copies of the Software, and to permit persons to whom the Software is
76+
furnished to do so, subject to the following conditions:
77+
78+
The above copyright notice and this permission notice shall be included in all
79+
copies or substantial portions of the Software.
80+
81+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
84+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
85+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
86+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
87+
SOFTWARE.
88+
6389
----------------------------------------------------------------------
6490
License notice for github.com/davecgh/go-spew
6591
----------------------------------------------------------------------
@@ -279,6 +305,31 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
279305
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
280306
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
281307

308+
----------------------------------------------------------------------
309+
License notice for github.com/tidwall/pretty
310+
----------------------------------------------------------------------
311+
312+
The MIT License (MIT)
313+
314+
Copyright (c) 2017 Josh Baker
315+
316+
Permission is hereby granted, free of charge, to any person obtaining a copy of
317+
this software and associated documentation files (the "Software"), to deal in
318+
the Software without restriction, including without limitation the rights to
319+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
320+
the Software, and to permit persons to whom the Software is furnished to do so,
321+
subject to the following conditions:
322+
323+
The above copyright notice and this permission notice shall be included in all
324+
copies or substantial portions of the Software.
325+
326+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
327+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
328+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
329+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
330+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
331+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
332+
282333
----------------------------------------------------------------------
283334
License notice for golang.org/x/crypto
284335
----------------------------------------------------------------------

bson/array_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestArray(t *testing.T) {
3434
defer func() {
3535
r := recover()
3636
if r != nil {
37-
t.Errorf("Recieved unexpected panic from nil insert. got %#v; want %#v", r, nil)
37+
t.Errorf("Received unexpected panic from nil insert. got %#v; want %#v", r, nil)
3838
}
3939
}()
4040
want := NewArray()

bson/decimal/decimal.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
// BSON library for Go
1+
// Copyright (C) MongoDB, Inc. 2017-present.
22
//
3-
// Copyright (c) 2010-2012 - Gustavo Niemeyer <[email protected]>
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
46
//
5-
// All rights reserved.
6-
//
7-
// Redistribution and use in source and binary forms, with or without
8-
// modification, are permitted provided that the following conditions are met:
9-
//
10-
// 1. Redistributions of source code must retain the above copyright notice, this
11-
// list of conditions and the following disclaimer.
12-
// 2. Redistributions in binary form must reproduce the above copyright notice,
13-
// this list of conditions and the following disclaimer in the documentation
14-
// and/or other materials provided with the distribution.
15-
//
16-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17-
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18-
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19-
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20-
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21-
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22-
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23-
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25-
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7+
// Based on gopkg.in/mgo.v2/bson by Gustavo Niemeyer
8+
// See THIRD-PARTY-NOTICES for original license terms.
269

2710
package decimal
2811

bson/document.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ func ReadDocument(b []byte) (*Document, error) {
9090
return doc, nil
9191
}
9292

93+
// Copy makes a shallow copy of this document.
94+
func (d *Document) Copy() *Document {
95+
if d == nil {
96+
return nil
97+
}
98+
99+
doc := &Document{
100+
IgnoreNilInsert: d.IgnoreNilInsert,
101+
elems: make([]*Element, len(d.elems), cap(d.elems)),
102+
index: make([]uint32, len(d.index), cap(d.index)),
103+
}
104+
105+
copy(doc.elems, d.elems)
106+
copy(doc.index, d.index)
107+
108+
return doc
109+
}
110+
93111
// Len returns the number of elements in the document.
94112
func (d *Document) Len() int {
95113
if d == nil {

bson/document_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestDocument(t *testing.T) {
106106
defer func() {
107107
r := recover()
108108
if r != nil {
109-
t.Errorf("Recieved unexpected panic from nil insert. got %#v; want %#v", r, nil)
109+
t.Errorf("Received unexpected panic from nil insert. got %#v; want %#v", r, nil)
110110
}
111111
}()
112112
want := NewDocument()
@@ -964,7 +964,7 @@ func TestDocument(t *testing.T) {
964964
t.Errorf("Unexpected error while converting document to extended json: %v", err)
965965
}
966966
if got != want {
967-
t.Errorf("Did not recieve expected result. got %s; want %s", got, want)
967+
t.Errorf("Did not receive expected result. got %s; want %s", got, want)
968968
}
969969
})
970970
t.Run("Relaxed", func(t *testing.T) {
@@ -975,7 +975,7 @@ func TestDocument(t *testing.T) {
975975
t.Errorf("Unexpected error while converting document to extended json: %v", err)
976976
}
977977
if got != want {
978-
t.Errorf("Did not recieve expected result. got %s; want %s", got, want)
978+
t.Errorf("Did not receive expected result. got %s; want %s", got, want)
979979
}
980980
})
981981
})

bson/encode.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,11 @@ func (e *encoder) encodeSliceAsArray(rval reflect.Value, minsize bool) ([]*Value
445445
vals = append(vals, VC.DateTime(convertTimeToInt64(t)))
446446
continue
447447
case *time.Time:
448-
vals = append(vals, VC.DateTime(convertTimeToInt64(*t)))
448+
if t == nil {
449+
vals = append(vals, VC.Null())
450+
} else {
451+
vals = append(vals, VC.DateTime(convertTimeToInt64(*t)))
452+
}
449453
continue
450454
}
451455

@@ -531,7 +535,11 @@ func (e *encoder) encodeStruct(val reflect.Value) ([]*Element, error) {
531535
elems = append(elems, EC.DateTime(key, convertTimeToInt64(t)))
532536
continue
533537
case *time.Time:
534-
elems = append(elems, EC.DateTime(key, convertTimeToInt64(*t)))
538+
if t == nil {
539+
elems = append(elems, EC.Null(key))
540+
} else {
541+
elems = append(elems, EC.DateTime(key, convertTimeToInt64(*t)))
542+
}
535543
continue
536544
}
537545
field = e.underlyingVal(field)

bson/encode_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,24 @@ func TestZeoerInterfaceUsedByDecoder(t *testing.T) {
11001100

11011101
}
11021102

1103+
type timePrtStruct struct{ TimePtrField *time.Time }
1104+
1105+
func TestRegressionNoDereferenceNilTimePtr(t *testing.T) {
1106+
enc := &encoder{}
1107+
1108+
assert.NotPanics(t, func() {
1109+
res, err := enc.encodeStruct(reflect.ValueOf(timePrtStruct{}))
1110+
assert.Len(t, res, 1)
1111+
assert.Nil(t, err)
1112+
})
1113+
1114+
assert.NotPanics(t, func() {
1115+
res, err := enc.encodeSliceAsArray(reflect.ValueOf([]*time.Time{nil, nil, nil}), false)
1116+
assert.Len(t, res, 3)
1117+
assert.Nil(t, err)
1118+
})
1119+
}
1120+
11031121
func docToBytes(d *Document) []byte {
11041122
b, err := d.MarshalBSON()
11051123
if err != nil {

bson/extjson_bson_corpus_spec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"testing"
1818
"unicode"
1919

20-
"github.com/mongodb/mongo-go-driver/bson/internal/jsonpretty"
2120
"github.com/stretchr/testify/require"
21+
"github.com/tidwall/pretty"
2222
)
2323

2424
type testCase struct {

bson/extjson_builder.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"fmt"
1212
"strconv"
1313

14+
"github.com/buger/jsonparser"
1415
"github.com/mongodb/mongo-go-driver/bson/builder"
15-
"github.com/mongodb/mongo-go-driver/bson/internal/jsonparser"
1616
)
1717

1818
type docElementParser func([]byte, []byte, jsonparser.ValueType, int) error
19-
type arrayElementParser func(int, []byte, jsonparser.ValueType, int) error
19+
type arrayElementParser func([]byte, jsonparser.ValueType, int, error)
2020

2121
// ParseExtJSONObject parses a JSON object string into a *Document.
2222
func ParseExtJSONObject(s string) (*Document, error) {
@@ -180,9 +180,11 @@ func parseDocElement(b *builder.DocumentBuilder, ext bool) docElementParser {
180180
}
181181

182182
func parseArrayElement(b *builder.ArrayBuilder, ext bool) arrayElementParser {
183-
return func(index int, value []byte, dataType jsonparser.ValueType, offset int) error {
184-
name := strconv.FormatInt(int64(index), 10)
183+
var index int64
184+
return func(value []byte, dataType jsonparser.ValueType, offset int, _ error) {
185+
name := strconv.FormatInt(index, 10)
186+
index++
185187

186-
return parseDocElement(&b.DocumentBuilder, ext)([]byte(name), value, dataType, offset)
188+
_ = parseDocElement(&b.DocumentBuilder, ext)([]byte(name), value, dataType, offset)
187189
}
188190
}

bson/extjson_parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"errors"
1111
"fmt"
1212

13+
"github.com/buger/jsonparser"
1314
"github.com/mongodb/mongo-go-driver/bson/builder"
14-
"github.com/mongodb/mongo-go-driver/bson/internal/jsonparser"
1515
)
1616

1717
type parseState struct {

bson/extjson_wrappers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"strconv"
1515
"time"
1616

17+
"github.com/buger/jsonparser"
1718
"github.com/mongodb/mongo-go-driver/bson/builder"
1819
"github.com/mongodb/mongo-go-driver/bson/decimal"
19-
"github.com/mongodb/mongo-go-driver/bson/internal/jsonparser"
2020
)
2121

2222
type wrapperType byte

0 commit comments

Comments
 (0)