Skip to content

Commit 797a221

Browse files
committed
#RI-5376 - update parsing redis url
1 parent 24f0757 commit 797a221

File tree

2 files changed

+19
-58
lines changed

2 files changed

+19
-58
lines changed

redisinsight/ui/src/utils/parseRedisUrl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ const parseRedisUrl = (urlString: string = ''): Nullable<ParsedRedisUrl> => {
3434
}
3535

3636
// eslint-disable-next-line no-useless-escape
37-
const redisUrlPattern = /^(redis[s]?):\/\/(?:([^:@]+)?(?::([^@]+))?@)?([^:\/]+)(?::(\d+))?(?:\/(\d+))?$/
37+
const redisUrlPattern = /^(redis[s]?):\/\/(?:([^\/]+)?@)?(?:.*@)?([^:\/]+)(?::(\d+))?(?:\/(\d+))?$/
3838
const match = urlString.match(redisUrlPattern)
3939

4040
if (!match) {
4141
return null
4242
}
4343

44-
const [, protocol, username, password, host, port, dbNumber] = match
44+
const [, protocol, userInfo, host, port, dbNumber] = match
45+
const [, username, password] = userInfo?.match(/^(.*?)(?::(.*))?$/) || []
4546

4647
return {
4748
protocol: protocol || 'redis',

redisinsight/ui/src/utils/tests/parseRedisUrl.spec.ts

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,22 @@ const defaultRedisParams = {
99
}
1010

1111
const parseRedisUrlTests: Array<[string, any]> = [
12-
[
13-
'http://user:pass@localhost:6380',
14-
null
15-
],
16-
[
17-
'redis://:@localhost:6380',
18-
null
19-
],
20-
[
21-
'redis://us@er:pass@localhost:6380',
22-
null
23-
],
24-
[
25-
'localhost',
26-
null
27-
],
28-
[
29-
'localhost:6379',
30-
{ ...defaultRedisParams, host: 'localhost', port: 6379 }
31-
],
32-
[
33-
'redis://localhost',
34-
{ ...defaultRedisParams, host: 'localhost' }
35-
],
36-
[
37-
'redis://localhost:6380',
38-
{ ...defaultRedisParams, host: 'localhost', port: 6380 }
39-
],
40-
[
41-
'redis://@localhost:6380',
42-
{ ...defaultRedisParams, host: 'localhost', port: 6380 }
43-
],
44-
[
45-
'redis://user@localhost:6380',
46-
{ ...defaultRedisParams, username: 'user', host: 'localhost', port: 6380 }
47-
],
48-
[
49-
'redis://:pass@localhost:6380',
50-
{ ...defaultRedisParams, password: 'pass', host: 'localhost', port: 6380 }
51-
],
52-
[
53-
'redis://user:pass@localhost:6380',
54-
{ ...defaultRedisParams, username: 'user', password: 'pass', host: 'localhost', port: 6380 }
55-
],
56-
[
57-
'rediss://user:pa%712ss@localhost:6380',
58-
{ ...defaultRedisParams, protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380 }
59-
],
60-
[
61-
'rediss://d&&21^$:pa%[email protected]:6380',
62-
{ ...defaultRedisParams, protocol: 'rediss', username: 'd&&21^$', password: 'pa%712ss', host: 'local-host-123.net.com', port: 6380 }
63-
],
64-
[
65-
'rediss://user:pa%712ss@localhost:6380/2',
66-
{ protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380, dbNumber: 2 }
67-
],
12+
['http://user:pass@localhost:6380', null],
13+
['localhost', null],
14+
['localhost:6379', { ...defaultRedisParams, host: 'localhost', port: 6379 }],
15+
['redis://localhost', { ...defaultRedisParams, host: 'localhost' }],
16+
['redis://:@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
17+
['redis://user:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'user', password: 'pa@ss' }],
18+
['redis://us@er:pa@ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'us@er', password: 'pa@ss' }],
19+
['redis://us@er:pa@:ss@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380, username: 'us@er', password: 'pa@:ss' }],
20+
['redis://localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
21+
['redis://@localhost:6380', { ...defaultRedisParams, host: 'localhost', port: 6380 }],
22+
['redis://user@localhost:6380', { ...defaultRedisParams, username: 'user', host: 'localhost', port: 6380 }],
23+
['redis://:pass@localhost:6380', { ...defaultRedisParams, password: 'pass', host: 'localhost', port: 6380 }],
24+
['redis://user:pass@localhost:6380', { ...defaultRedisParams, username: 'user', password: 'pass', host: 'localhost', port: 6380 }],
25+
['rediss://user:pa%712ss@localhost:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380 }],
26+
['rediss://d&@&21^$:pa%@7:12:[email protected]:6380', { ...defaultRedisParams, protocol: 'rediss', username: 'd&@&21^$', password: 'pa%@7:12:ss', host: 'local-host-123.net.com', port: 6380 }],
27+
['rediss://user:pa%712ss@localhost:6380/2', { protocol: 'rediss', username: 'user', password: 'pa%712ss', host: 'localhost', port: 6380, dbNumber: 2 }],
6828
]
6929

7030
describe('parseRedisUrl', () => {

0 commit comments

Comments
 (0)