diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-16 06:09:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-16 06:09:14 +0300 |
commit | 78fe72d153260c355fdfd533b125026cce310da7 (patch) | |
tree | 0d90106443bea87cc24e2834273ae6c8dcac0260 /app/models/application_setting_implementation.rb | |
parent | 88797b994a7dfd9bfab2a5d5431f088f17078b9f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/application_setting_implementation.rb')
-rw-r--r-- | app/models/application_setting_implementation.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index d1a919fc01a..5ad382d8670 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -361,18 +361,33 @@ module ApplicationSettingImplementation def separate_whitelists(string_array) string_array.reduce([[], []]) do |(ip_whitelist, domain_whitelist), string| - ip_obj = Gitlab::Utils.string_to_ip_object(string) + address, port = parse_addr_and_port(string) + + ip_obj = Gitlab::Utils.string_to_ip_object(address) if ip_obj - ip_whitelist << ip_obj + ip_whitelist << Gitlab::UrlBlockers::IpWhitelistEntry.new(ip_obj, port: port) else - domain_whitelist << string + domain_whitelist << Gitlab::UrlBlockers::DomainWhitelistEntry.new(address, port: port) end [ip_whitelist, domain_whitelist] end end + def parse_addr_and_port(str) + case str + when /\A\[(?<address> .* )\]:(?<port> \d+ )\z/x # string like "[::1]:80" + address, port = $~[:address], $~[:port] + when /\A(?<address> [^:]+ ):(?<port> \d+ )\z/x # string like "127.0.0.1:80" + address, port = $~[:address], $~[:port] + else # string with no port number + address, port = str, nil + end + + [address, port&.to_i] + end + def array_to_string(arr) arr&.join("\n") end |