Skip to content

connection string parsing is invalid #1704

@rafipiccolo

Description

@rafipiccolo

static parseUrl(url) {

To parse the connection string, we use "new Url(xxx)" but it looks like it urlencodes the parameters : Hence invalidating them when there are special chars.

imagine the password is xx^xx

the connection string can be :
mysql://root:xx^[email protected]/xx?charset=utf8mb4
or
mysql://root:xx%[email protected]/xx?charset=utf8mb4
both usually work in other libs.

it's worth noting that "new Url()" returns in both cases "password: xx%5Exx"
then ofc the connection cant be established because the password is wrong.

Since we use new Url, we should pass the "password" through decodeURIComponent to get it correctly.

IMHO valid parser would be :

const options = {
      host: parsedUrl.hostname,
      port: parsedUrl.port,
      database: parsedUrl.pathname.slice(1),
      user: parsedUrl.username,
      password: decodeURIComponent(parsedUrl.password)
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions