Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Parse url with encoded hash in password #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/event_store/config/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule EventStore.Config.Parser do
defp parse_url(""), do: []

defp parse_url(url) do
info = url |> URI.decode() |> URI.parse()
info = URI.parse(url)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for URI.decode/1 give this example:

iex> URI.decode("https%3A%2F%2Felixir-lang.org")
"https://elixir-lang.org"

Was that the purpose of this invocation?
The eventstore docs and tests don't mention that an encoded DATABASE_URL is supported, though.

As a reference, Ecto.Repo also does not seem to support that.


if is_nil(info.host) do
raise ArgumentError, message: "host is not present"
Expand Down
16 changes: 16 additions & 0 deletions test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ defmodule EventStore.ConfigTest do
)
end

test "parse url with encoded hash in password" do
config = [url: "postgres://username:password%23with_hash@localhost/database"]

assert_parsed_config(config,
enable_hard_deletes: false,
column_data_type: "bytea",
schema: "public",
timeout: 15_000,
pool: EventStore.Config.get_pool(),
username: "username",
password: "password#with_hash",
database: "database",
hostname: "localhost"
)
end

test "parse session_mode_url" do
config = [session_mode_url: "postgres://username:password@localhost/database"]

Expand Down