-
Notifications
You must be signed in to change notification settings - Fork 929
Make option parsing more conformant to libpq behaviour. #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -678,28 +678,35 @@ func TestParseOpts(t *testing.T) { | |
{"dbname=hello user= goodbye", values{"dbname": "hello", "user": "goodbye"}, true}, | ||
{"host=localhost password='correct horse battery staple'", values{"host": "localhost", "password": "correct horse battery staple"}, true}, | ||
{"dbname=データベース password=パスワード", values{"dbname": "データベース", "password": "パスワード"}, true}, | ||
{"dbname=hello user=''", values{"dbname": "hello", "user": ""}, true}, | ||
{"user='' dbname=hello", values{"dbname": "hello", "user": ""}, true}, | ||
// The last option value is an empty string if there's no non-whitespace after its = | ||
{"dbname=hello user= ", values{"dbname": "hello", "user": ""}, true}, | ||
|
||
// The parser ignores spaces after = and interprets the next set of non-whitespace characters as the value. | ||
{"user= password=foo", values{"user": "password=foo"}, true}, | ||
|
||
// The parser ignores trailing keys | ||
{"user=foo blah", values{"user": "foo"}, true}, | ||
{"user=foo blah ", values{"user": "foo"}, true}, | ||
{"user=foo blah= ", values{"user": "foo"}, true}, | ||
|
||
// No '=' after the key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment applies to the unchanged line below, I believe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It applies to all four tests here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, I guess that's true. The URL format threw me off. |
||
{"postgre://marko@internet", values{}, false}, | ||
{"dbname user=goodbye", values{}, false}, | ||
{"user=foo blah", values{}, false}, | ||
{"user=foo blah ", values{}, false}, | ||
|
||
// Unterminated quoted value | ||
{"dbname=hello user='unterminated", values{}, false}, | ||
} | ||
|
||
for _, test := range tests { | ||
o := make(values) | ||
err := parseOpts(test.in, o) | ||
if err != nil && test.valid { | ||
|
||
switch { | ||
case err != nil && test.valid: | ||
t.Errorf("%q got unexpected error: %s", test.in, err) | ||
} else if err == nil && !reflect.DeepEqual(test.expected, o) { | ||
case err == nil && test.valid && !reflect.DeepEqual(test.expected, o): | ||
t.Errorf("%q got: %#v want: %#v", test.in, o, test.expected) | ||
case err == nil && !test.valid: | ||
t.Errorf("%q expected an error", test.in) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens with this case now? Is it no longer relevant? Or do you think it was redundant to begin with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two of them moved down to the cases below. blah= is actually valid and moved up to the tests above.