Skip to content

the connection string is parsed wrongly #2561

Open
@its-dibo

Description

@its-dibo

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions