Skip to content

Commit

Permalink
GODRIVER-2305 Correctly append empty tagset from URI (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjirewis committed Feb 17, 2022
1 parent 624e7a3 commit c5019a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion x/mongo/driver/connstring/connstring.go
Expand Up @@ -746,7 +746,9 @@ func (p *parser) addOption(pair string) error {
p.ReadPreference = value
case "readpreferencetags":
if value == "" {
// for when readPreferenceTags= at end of URI
// If "readPreferenceTags=" is supplied, append an empty map to tag sets to
// represent a wild-card.
p.ReadPreferenceTagSets = append(p.ReadPreferenceTagSets, map[string]string{})
break
}

Expand Down
4 changes: 2 additions & 2 deletions x/mongo/driver/connstring/connstring_test.go
Expand Up @@ -382,8 +382,8 @@ func TestReadPreferenceTags(t *testing.T) {
{s: "readPreferenceTags=one:1,two:2", expected: []map[string]string{{"one": "1", "two": "2"}}},
{s: "readPreferenceTags=one:1&readPreferenceTags=two:2", expected: []map[string]string{{"one": "1"}, {"two": "2"}}},
{s: "readPreferenceTags=one:1:3,two:2", err: true},
{s: "readPreferenceTags=one:1&readPreferenceTags=two:2&readPreferenceTags=", expected: []map[string]string{{"one": "1"}, {"two": "2"}}},
{s: "readPreferenceTags=", expected: nil},
{s: "readPreferenceTags=one:1&readPreferenceTags=two:2&readPreferenceTags=", expected: []map[string]string{{"one": "1"}, {"two": "2"}, {}}},
{s: "readPreferenceTags=", expected: []map[string]string{{}}},
}

for _, test := range tests {
Expand Down

0 comments on commit c5019a7

Please sign in to comment.