Skip to content

Commit

Permalink
Fix, Test issue of readPreferenceTags= in URI
Browse files Browse the repository at this point in the history
GODRIVER-1078

If URI ends with readPreferenceTags= then we just ignore that additional
tag. Tests added ensure that this additional element of the URI is
ignored

Change-Id: Ic3e1385c98156f831055da2570a8d908d95248b6
  • Loading branch information
eppingere committed Jun 4, 2019
1 parent ff04022 commit 5da0272
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions x/network/connstring/connstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ func (p *parser) addOption(pair string) error {
case "readpreference":
p.ReadPreference = value
case "readpreferencetags":
if value == "" {
// for when readPreferenceTags= at end of URI
break
}

tags := make(map[string]string)
items := strings.Split(value, ",")
for _, item := range items {
Expand Down
3 changes: 3 additions & 0 deletions x/network/connstring/connstring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,13 @@ func TestReadPreferenceTags(t *testing.T) {
expected []map[string]string
err bool
}{
{s: "", expected: nil},
{s: "readPreferenceTags=one:1", expected: []map[string]string{{"one": "1"}}},
{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},
}

for _, test := range tests {
Expand Down

0 comments on commit 5da0272

Please sign in to comment.