Skip to content

Commit 4825420

Browse files
author
Nghĩa Nguyễn Ngọc
committed
dsn: document that usernames with colons require NewConfig()
The DSN format uses ':' as the user/password separator, making it impossible to represent a username that contains a colon without ambiguity. There is no safe way to fix this in ParseDSN without breaking existing users who rely on the current first-colon behaviour for passwords that contain colons. Instead, document the limitation clearly in the ParseDSN godoc and point callers to NewConfig(), which has no such ambiguity. Fixes #1747
1 parent a065b60 commit 4825420

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

dsn.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ func (cfg *Config) FormatDSN() string {
392392
return buf.String()
393393
}
394394

395-
// ParseDSN parses the DSN string to a Config
395+
// ParseDSN parses the DSN string to a Config.
396+
//
397+
// The DSN format is [user[:password]@][net[(addr)]]/dbname[?params].
398+
// Because the colon is used as the user/password separator, usernames that
399+
// contain a colon cannot be represented unambiguously in the DSN string format.
400+
// If your username contains a colon, use [NewConfig] and set the fields directly
401+
// instead of constructing a DSN string.
396402
func ParseDSN(dsn string) (cfg *Config, err error) {
397403
// New config with some default values
398404
cfg = NewConfig()

0 commit comments

Comments
 (0)