Skip to content

Commit 3f90528

Browse files
awhwrouesnel
authored andcommitted
URL encode username/password fields
Fixes #188.
1 parent 9eff17a commit 3f90528

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

cmd/postgres_exporter/postgres_exporter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,9 @@ func getDataSource() string {
10861086
pass = os.Getenv("DATA_SOURCE_PASS")
10871087
}
10881088

1089+
ui := url.UserPassword(user, pass).String()
10891090
uri := os.Getenv("DATA_SOURCE_URI")
1090-
dsn = "postgresql://" + user + ":" + pass + "@" + uri
1091+
dsn = "postgresql://" + ui + "@" + uri
10911092
}
10921093

10931094
return dsn

cmd/postgres_exporter/postgres_exporter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (s *FunctionalSuite) TestEnvironmentSettingWithSecretsFiles(c *C) {
105105
c.Assert(err, IsNil)
106106
defer UnsetEnvironment(c, "DATA_SOURCE_URI")
107107

108-
var expected = "postgresql://custom_username:custom_password@localhost:5432/?sslmode=disable"
108+
var expected = "postgresql://custom_username$&+,%2F%3A;=%3F%40:custom_password$&+,%2F%3A;=%3F%40@localhost:5432/?sslmode=disable"
109109

110110
dsn := getDataSource()
111111
if dsn != expected {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
custom_username
1+
custom_username$&+,/:;=?@
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
custom_password
1+
custom_password$&+,/:;=?@

0 commit comments

Comments
 (0)