bugfix: improve regexp

Discovered that code did not handle connection strings with punctuations.
This is now improved.
This commit is contained in:
Nils Norman Haukås 2018-05-19 23:27:21 +02:00
parent eaf96df871
commit f5d0e06b52
2 changed files with 5 additions and 5 deletions

2
lib.js
View File

@ -7,7 +7,7 @@ function parseUri(uri) {
host,
port,
database
] = /(\w*):\/\/(\w*):(\w*)@([\w|\.|-]*):(\d*)\/(\w*)/g.exec(uri)
] = /(\w*):\/\/(.*):(.*)@(.*):(\d*)\/(\w*)/g.exec(uri)
return { scheme, user, host, password, port, database }
}

View File

@ -3,11 +3,11 @@ import { parseUri, buildMysqlParams } from './lib'
test('should be able to parse fully formed url', t => {
const testUrl =
'mysql://asdf123123:zxcvasdf234789@example123.org.somewhere-here.com:3306/khe4zx5encg0ao15'
'mysql://asdf123123:zxcvas.df234789@example123.org.somewhere-here.com:3306/khe4zx5encg0ao15'
t.deepEqual(parseUri(testUrl), {
scheme: 'mysql',
user: 'asdf123123',
password: 'zxcvasdf234789',
password: 'zxcvas.df234789',
host: 'example123.org.somewhere-here.com',
port: '3306',
database: 'khe4zx5encg0ao15'
@ -17,10 +17,10 @@ test('should be able to parse fully formed url', t => {
test('should be able to prepare mysql connection parameters', t => {
const has = (str, target) => str.indexOf(target) !== -1
const testUrl =
'mysql://asdf123123:zxcvasdf234789@example123.org.somewhere-here.com:3306/khe4zx5encg0ao15'
'mysql://asdf123123:zxcvas.df234789@example123.org.somewhere-here.com:3306/khe4zx5encg0ao15'
t.is(
buildMysqlParams(testUrl),
'-u asdf123123 -pzxcvasdf234789 -h example123.org.somewhere-here.com -P 3306 khe4zx5encg0ao15',
'-u asdf123123 -pzxcvas.df234789 -h example123.org.somewhere-here.com -P 3306 khe4zx5encg0ao15',
'was not able to generate correct cmd connection string'
)
})