Skip to content

Commit fb62199

Browse files
Merge pull request #1979 from mongodb/merge-release/2.0-into-release/2.1-1741365148192
Merge release/2.0 into release/2.1
2 parents db72684 + 4f74072 commit fb62199

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

bson/bson_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,20 @@ func TestMapCodec(t *testing.T) {
584584
}
585585

586586
func TestExtJSONEscapeKey(t *testing.T) {
587-
doc := D{{Key: "\\usb#", Value: int32(1)}}
587+
doc := D{
588+
{
589+
Key: "\\usb#",
590+
Value: int32(1),
591+
},
592+
{
593+
Key: "regex",
594+
Value: Regex{Pattern: "ab\\\\\\\"ab", Options: "\""},
595+
},
596+
}
588597
b, err := MarshalExtJSON(&doc, false, false)
589598
noerr(t, err)
590599

591-
want := "{\"\\\\usb#\":1}"
600+
want := `{"\\usb#":1,"regex":{"$regularExpression":{"pattern":"ab\\\\\\\"ab","options":"\""}}}`
592601
if diff := cmp.Diff(want, string(b)); diff != "" {
593602
t.Errorf("Marshaled documents do not match. got %v, want %v", string(b), want)
594603
}

bson/extjson_writer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,13 @@ func (ejvw *extJSONValueWriter) WriteRegex(pattern string, options string) error
407407
return err
408408
}
409409

410+
options = sortStringAlphebeticAscending(options)
410411
var buf bytes.Buffer
411412
buf.WriteString(`{"$regularExpression":{"pattern":`)
412413
writeStringWithEscapes(pattern, &buf, ejvw.escapeHTML)
413-
buf.WriteString(`,"options":"`)
414-
buf.WriteString(sortStringAlphebeticAscending(options))
415-
buf.WriteString(`"}},`)
414+
buf.WriteString(`,"options":`)
415+
writeStringWithEscapes(options, &buf, ejvw.escapeHTML)
416+
buf.WriteString(`}},`)
416417

417418
ejvw.buf = append(ejvw.buf, buf.Bytes()...)
418419

0 commit comments

Comments
 (0)