Skip to content

Username with a ':' fails. #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nemith opened this issue Oct 20, 2017 · 2 comments
Closed

Username with a ':' fails. #688

nemith opened this issue Oct 20, 2017 · 2 comments
Labels

Comments

@nemith
Copy link
Contributor

nemith commented Oct 20, 2017

Issue description

Due to how the dsn decoding is done any username with a ':' fails. We have a system at my job where ':' are required.

Since there is no url.QueryUnescape() on the username adding the proper escapes, like standard based URI, doesn't work. It will either be treated as a password incorrectly or the escaped value will be never unescaped and so the user will fail.

Adding a url.QueryUnescape into dsn.go fixes the issue for me.

Example code

// unescaped treats it like a password (which is ok)
db.Open('mysql', "foo:bar@tcp(localhost)")

// escaped should work
db.Open('mysql', "foo%3Abar@tcp(localhost)")
@julienschmidt
Copy link
Member

See #591.
I'm afraid you have to either patch the driver or get rid of the :s.

@nemith
Copy link
Contributor Author

nemith commented Oct 20, 2017

That is super unfortunate. Changing username is not an option. Forking i guess it is.

Ever consider using url.Parse and looking for a u.Schema of 'mysql'. If the URL cannot be parsed or the schema is missing fall back to the old parsing. If it is there then use a better form of parsing.

Postgres's go driver does something like this.

liuxinbot pushed a commit to liuxinbot/mysql that referenced this issue Jan 17, 2023
Sometimes usernames may have characters that need encoding such as : or
@.  This fixes the problem by url escaping the username on FormatDSN and
unescaping it on ParseDSN.

Although the DSNs are not proper URIs escaping of username is defined in
https://www.ietf.org/rfc/rfc3986.txt

Fixes: go-sql-driver#688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants