Skip to content
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

the connection string is parsed wrongly #2561

Open
its-dibo opened this issue Feb 17, 2023 · 1 comment
Open

the connection string is parsed wrongly #2561

its-dibo opened this issue Feb 17, 2023 · 1 comment
Assignees
Labels

Comments

@its-dibo
Copy link

the method createConnection accepts a connection URL as a string or an object of type ConnectionConfig
if a string is passed, it uses require('url').parse to parse the string and returns a connection object.

this approach assumes that the property pathname that is returned by url.parse has a string value, but in fact, it returns null when providing a port which is an integer

example
let's parse this connection URL string mysql://username:password@host:1234

const urlParse = require('url').parse;

let url = "mysql://username:password@host:123",
 parsed = urlParse(url, true);

console.log(parsed)

output:

 {
  protocol: 'mysql:',
  slashes: true,
  auth: 'username:password',
  host: 'host:123',
  port: '123',
  hostname: 'host',
  hash: null,
  search: null,
  query: [Object: null prototype] {},
  pathname: null, // <----------------------------------
  path: null,
  href: 'mysql://username:password@host:123'
}

note that pathname here is null

@dougwilson
Copy link
Member

Good catch. We can fix the module to properly handle null, as it should be the same as just no database like otherwise. Sorry for that bug, it is an easy fix.

@dougwilson dougwilson added the bug label Nov 20, 2023
@dougwilson dougwilson self-assigned this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants