From 5c52acd8004c229a261cd7c4a43a1efbdc705530 Mon Sep 17 00:00:00 2001 From: Fredrik Teschke Date: Tue, 27 Jun 2023 08:37:05 +0200 Subject: [PATCH] Parse url with encoded hash in password --- lib/event_store/config/parser.ex | 2 +- test/config_test.exs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/event_store/config/parser.ex b/lib/event_store/config/parser.ex index 5ff8c3d9..70b16205 100644 --- a/lib/event_store/config/parser.ex +++ b/lib/event_store/config/parser.ex @@ -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) if is_nil(info.host) do raise ArgumentError, message: "host is not present" diff --git a/test/config_test.exs b/test/config_test.exs index e46eccf1..6d5e848c 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -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"]