diff --git a/config/config.go b/config/config.go index 713835c23..a20aefda9 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/config/config_test.go b/config/config_test.go index a282efcfc..cbb354c8d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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) { diff --git a/config/testdata/comment_char_in_password.cnf b/config/testdata/comment_char_in_password.cnf new file mode 100644 index 000000000..68637c7d4 --- /dev/null +++ b/config/testdata/comment_char_in_password.cnf @@ -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