Merge pull request #7772 from galxy25/kava-fix-database-url-password-period-parsing

Fix parsing of database password period(s)
pull/7823/head
Victor Baranov 1 year ago committed by GitHub
commit 952cd7fb6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/lib/explorer/repo/config_helper.ex
  3. 4
      apps/explorer/test/explorer/repo/config_helper_test.exs

@ -6,6 +6,7 @@
### Fixes ### Fixes
- [#7772](https://github.com/blockscout/blockscout/pull/7772) - Fix parsing of database password period(s)
- [#7803](https://github.com/blockscout/blockscout/pull/7803) - Fix additional sources and interfaces, save names for vyper contracts - [#7803](https://github.com/blockscout/blockscout/pull/7803) - Fix additional sources and interfaces, save names for vyper contracts
- [#7758](https://github.com/blockscout/blockscout/pull/7758) - Remove limit for configurable fetchers - [#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 - [#7764](https://github.com/blockscout/blockscout/pull/7764) - Fix missing ranges insertion and deletion logic

@ -36,7 +36,7 @@ defmodule Explorer.Repo.ConfigHelper do
# sobelow_skip ["DOS.StringToAtom"] # sobelow_skip ["DOS.StringToAtom"]
defp extract_parameters(database_url) do defp extract_parameters(database_url) do
~r/\w*:\/\/(?<username>[a-zA-Z0-9_-]*):(?<password>[a-zA-Z0-9-*#!%^&$_]*)?@(?<hostname>(([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])):(?<port>\d+)\/(?<database>[a-zA-Z0-9_-]*)/ ~r/\w*:\/\/(?<username>[a-zA-Z0-9_-]*):(?<password>[a-zA-Z0-9-*#!%^&$_.]*)?@(?<hostname>(([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])):(?<port>\d+)\/(?<database>[a-zA-Z0-9_-]*)/
|> Regex.named_captures(database_url) |> Regex.named_captures(database_url)
|> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end) |> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end)
|> Keyword.put(:url, database_url) |> Keyword.put(:url, database_url)

@ -53,12 +53,12 @@ defmodule Explorer.Repo.ConfigHelperTest do
end end
test "parse params from database url with special characters in password" do 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}) result = ConfigHelper.get_db_config(%{url: database_url, env_func: fn _ -> nil end})
assert result[:username] == "test_username" 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[:hostname] == "hostname.test.com"
assert result[:port] == "7777" assert result[:port] == "7777"
assert result[:database] == "test_database" assert result[:database] == "test_database"

Loading…
Cancel
Save