From 0acc4257b8cb0e1b4a9c4d67253715b01d31cb75 Mon Sep 17 00:00:00 2001 From: Levi Schoen Date: Thu, 22 Jun 2023 16:12:44 -0700 Subject: [PATCH] Fix parsing of database password period(s) --- CHANGELOG.md | 1 + apps/explorer/lib/explorer/repo/config_helper.ex | 2 +- apps/explorer/test/explorer/repo/config_helper_test.exs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 943b528615..8e076df564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes +- [#7772](https://github.com/blockscout/blockscout/pull/7772) - Fix parsing of database password period(s) - [#7758](https://github.com/blockscout/blockscout/pull/7758) - Remove limit for configurable fetchers - [#7764](https://github.com/blockscout/blockscout/pull/7764) - Fix missing ranges insertion and deletion logic diff --git a/apps/explorer/lib/explorer/repo/config_helper.ex b/apps/explorer/lib/explorer/repo/config_helper.ex index edf73d4dbd..d8ccf18008 100644 --- a/apps/explorer/lib/explorer/repo/config_helper.ex +++ b/apps/explorer/lib/explorer/repo/config_helper.ex @@ -36,7 +36,7 @@ defmodule Explorer.Repo.ConfigHelper do # sobelow_skip ["DOS.StringToAtom"] defp extract_parameters(database_url) do - ~r/\w*:\/\/(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9-*#!%^&$_]*)?@(?(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])):(?\d+)\/(?[a-zA-Z0-9_-]*)/ + ~r/\w*:\/\/(?[a-zA-Z0-9_-]*):(?[a-zA-Z0-9-*#!%^&$_.]*)?@(?(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])):(?\d+)\/(?[a-zA-Z0-9_-]*)/ |> Regex.named_captures(database_url) |> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end) |> Keyword.put(:url, database_url) diff --git a/apps/explorer/test/explorer/repo/config_helper_test.exs b/apps/explorer/test/explorer/repo/config_helper_test.exs index 06ba3a03db..71bb85077e 100644 --- a/apps/explorer/test/explorer/repo/config_helper_test.exs +++ b/apps/explorer/test/explorer/repo/config_helper_test.exs @@ -53,12 +53,12 @@ defmodule Explorer.Repo.ConfigHelperTest do end test "parse params from database url with special characters in password" do - database_url = "postgresql://test_username:awN!l#W*g$P%t-l^q&d@hostname.test.com:7777/test_database" + database_url = "postgresql://test_username:awN!l#W*g$P%t-l^.q&d@hostname.test.com:7777/test_database" result = ConfigHelper.get_db_config(%{url: database_url, env_func: fn _ -> nil end}) assert result[:username] == "test_username" - assert result[:password] == "awN!l#W*g$P%t-l^q&d" + assert result[:password] == "awN!l#W*g$P%t-l^.q&d" assert result[:hostname] == "hostname.test.com" assert result[:port] == "7777" assert result[:database] == "test_database"