Skip to content

Commit 37c6daf

Browse files
authored
fix: password contains colons (#1274)
1 parent be5d53f commit 37c6daf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Diff for: lib/utils/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ export function parseURL(url) {
257257

258258
const result: any = {};
259259
if (parsed.auth) {
260-
const parsedAuth = parsed.auth.split(":");
261-
result.password = parsedAuth[1];
260+
const index = parsed.auth.indexOf(":")
261+
result.password = index === -1 ? '' : parsed.auth.slice(index + 1)
262262
}
263263
if (parsed.pathname) {
264264
if (parsed.protocol === "redis:" || parsed.protocol === "rediss:") {

Diff for: test/unit/utils.ts

+18
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,24 @@ describe("utils", function () {
195195
password: "pass",
196196
key: "value",
197197
});
198+
expect(
199+
utils.parseURL("redis://user:pass:[email protected]:6380/4?key=value")
200+
).to.eql({
201+
host: "127.0.0.1",
202+
port: "6380",
203+
db: "4",
204+
password: "pass:word",
205+
key: "value",
206+
});
207+
expect(
208+
utils.parseURL("redis://[email protected]:6380/4?key=value")
209+
).to.eql({
210+
host: "127.0.0.1",
211+
port: "6380",
212+
db: "4",
213+
password: "",
214+
key: "value",
215+
});
198216
expect(utils.parseURL("redis://127.0.0.1/")).to.eql({
199217
host: "127.0.0.1",
200218
});

0 commit comments

Comments
 (0)