Merge pull request #5241 from blockscout/vb-fix-host-name-regex-pattern

Fix DB hostname Regex pattern
pull/5230/head
Victor Baranov 3 years ago committed by GitHub
commit 49e8dfbe8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 1
      CHANGELOG.md
  3. 2
      apps/explorer/lib/explorer/repo/config_helper.ex
  4. 12
      apps/explorer/test/explorer/repo/config_helper_test.exs

1
.gitignore vendored

@ -44,3 +44,4 @@ screenshots/
/apps/block_scout_web/priv/cert
/docker-compose/postgres-data
/docker-compose/tmp

@ -8,6 +8,7 @@
- [#4690](https://github.com/blockscout/blockscout/pull/4690) - Improve pagination: introduce pagination with random access to pages; Integrate it to the Transactions List page
### Fixes
- [#5241](https://github.com/blockscout/blockscout/pull/5241) - Fix DB hostname Regex pattern
- [#5216](https://github.com/blockscout/blockscout/pull/5216) - Add token-transfers-toggle.js to the `block_transaction/index.html.eex`
- [#5212](https://github.com/blockscout/blockscout/pull/5212) - Fix `gas_used` value bug
- [#5197](https://github.com/blockscout/blockscout/pull/5197) - Fix contract functions outputs

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

@ -16,6 +16,18 @@ defmodule Explorer.Repo.ConfigHelperTest do
assert result[:database] == "test_database"
end
test "parse params from database url with hyphen in hostname" do
database_url = "postgresql://test_username:test_password@host-name.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] == "test_password"
assert result[:hostname] == "host-name.test.com"
assert result[:port] == "7777"
assert result[:database] == "test_database"
end
test "get username without password" do
database_url = "postgresql://test_username:@127.8.8.1:7777/test_database"

Loading…
Cancel
Save