Skip to content

Commit 299cde2

Browse files
authored
Correctly extract passwords with colons from URL (#4709)
1 parent b8e406d commit 299cde2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/ecto/repo/supervisor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Ecto.Repo.Supervisor do
111111
raise Ecto.InvalidURLError, url: url, message: "path should be a database name"
112112
end
113113

114-
destructure [username, password], info.userinfo && String.split(info.userinfo, ":")
114+
destructure [username, password], info.userinfo && String.split(info.userinfo, ":", parts: 2)
115115
"/" <> database = info.path
116116

117117
url_opts = [

test/ecto/repo/supervisor_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ defmodule Ecto.Repo.SupervisorTest do
152152
refute Keyword.has_key?(url, :password)
153153
end
154154

155+
test "parses password containing colons" do
156+
url = parse_url("ecto://user:top:secret@host:12345/mydb")
157+
assert {:password, "top:secret"} in url
158+
assert {:username, "user"} in url
159+
end
160+
155161
test "parses multiple query string options" do
156162
encoded_url = URI.encode("ecto://eric:it+й@host:12345/mydb?ssl=true&timeout=1515")
157163
url = parse_url(encoded_url)

0 commit comments

Comments
 (0)