Skip to content

Commit

Permalink
Don't die on trailing whitespace in a connection string
Browse files Browse the repository at this point in the history
Currently, if you give pq a connection string with a trailing
whitespace, pq likes to die with the confusing message pq: invalid
option: ""

This patch just trims whitespace around the connection string so that
when parseOptions splits on " ", it doesn't get a spurious empty
option.

Editorialized by Daniel Farina <[email protected]>
  • Loading branch information
llimllib authored and fdr committed Jun 7, 2013
1 parent 592007b commit d0047d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func parseOpts(name string, o Values) {
return
}

name = strings.TrimSpace(name)

ps := strings.Split(name, " ")
for _, p := range ps {
kv := strings.Split(p, "=")
Expand Down
9 changes: 9 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,12 @@ func TestRollback(t *testing.T) {
t.Fatal("Transaction rollback failed")
}
}

func TestConnTrailingSpace(t *testing.T) {
o := make(Values)
expected := Values{"dbname": "hello", "user": "goodbye"}
parseOpts("dbname=hello user=goodbye ", o)
if !reflect.DeepEqual(expected, o) {
t.Fatalf("Expected: %#v Got: %#v", expected, o)
}
}

0 comments on commit d0047d4

Please sign in to comment.