Skip to content

Commit

Permalink
fix: password contains colons (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
fishioon authored Jan 14, 2021
1 parent be5d53f commit 37c6daf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ export function parseURL(url) {

const result: any = {};
if (parsed.auth) {
const parsedAuth = parsed.auth.split(":");
result.password = parsedAuth[1];
const index = parsed.auth.indexOf(":")
result.password = index === -1 ? '' : parsed.auth.slice(index + 1)
}
if (parsed.pathname) {
if (parsed.protocol === "redis:" || parsed.protocol === "rediss:") {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,24 @@ describe("utils", function () {
password: "pass",
key: "value",
});
expect(
utils.parseURL("redis://user:pass:[email protected]:6380/4?key=value")
).to.eql({
host: "127.0.0.1",
port: "6380",
db: "4",
password: "pass:word",
key: "value",
});
expect(
utils.parseURL("redis://[email protected]:6380/4?key=value")
).to.eql({
host: "127.0.0.1",
port: "6380",
db: "4",
password: "",
key: "value",
});
expect(utils.parseURL("redis://127.0.0.1/")).to.eql({
host: "127.0.0.1",
});
Expand Down

0 comments on commit 37c6daf

Please sign in to comment.