Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
Loose: true,
// MySQL ini file can have boolean keys.
AllowBooleanKeys: true,
// Allow comment characters inside values.
SpaceBeforeInlineComment: true,
}

err error
Expand Down
22 changes: 22 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ func TestValidateConfig(t *testing.T) {
convey.So(section.User, convey.ShouldEqual, "abc")
convey.So(section.Password, convey.ShouldEqual, "")
})

convey.Convey("Comment characters in password", t, func() {
c := MySqlConfigHandler{
Config: &Config{},
}
if err := c.ReloadConfig("testdata/comment_char_in_password.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil {
t.Error(err)
}
cfg := c.GetConfig()
convey.Convey("hash", func() {
section := cfg.Sections["client.hash"]
convey.So(section.Password, convey.ShouldEqual, "abc#xyz")
})
convey.Convey("semicolon", func() {
section := cfg.Sections["client.semicolon"]
convey.So(section.Password, convey.ShouldEqual, "abc;xyz")
})
convey.Convey("hash and semicolon", func() {
section := cfg.Sections["client.both"]
convey.So(section.Password, convey.ShouldEqual, "abc#xyz;pqr")
})
})
}

func TestFormDSN(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions config/testdata/comment_char_in_password.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[client.hash]
user = test
password = abc#xyz
[client.semicolon]
user = test
password = abc;xyz
[client.both]
user = test
password = abc#xyz;pqr