Skip to content

Commit ca7d6d2

Browse files
authored
Merge pull request #1253 from OS-M/empty-db-dsn-fix
Fixed empty database in DSN while using config.WithDatabase
2 parents b262476 + 3536190 commit ca7d6d2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Fixed `config.WithDatabase` behaviour with empty database in DSN string
12
* Added experimental method `query/Client.Execute` for execute query and read materialized result
23

34
## v3.69.0

internal/dsn/dsn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ func Parse(dsn string) (info parsedInfo, err error) {
3535
info.Options = append(info.Options,
3636
config.WithSecure(uri.Scheme != insecureSchema),
3737
config.WithEndpoint(uri.Host),
38-
config.WithDatabase(uri.Path),
3938
)
39+
if uri.Path != "" {
40+
info.Options = append(info.Options, config.WithDatabase(uri.Path))
41+
}
4042
if uri.User != nil {
4143
password, _ := uri.User.Password()
4244
info.UserInfo = &UserInfo{

internal/dsn/dsn_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,15 @@ func TestParseConnectionString(t *testing.T) {
124124
})
125125
}
126126
}
127+
128+
func TestParseConnectionStringEmptyDatabase(t *testing.T) {
129+
info, err := Parse("grpc://ydb-ru.yandex.net:2135")
130+
if err != nil {
131+
t.Fatalf("Received unexpected error:\n%+v", err)
132+
}
133+
c := config.New(config.WithDatabase("mydb"))
134+
c = c.With(info.Options...)
135+
require.False(t, c.Secure())
136+
require.Equal(t, "ydb-ru.yandex.net:2135", c.Endpoint())
137+
require.Equal(t, "mydb", c.Database())
138+
}

0 commit comments

Comments
 (0)