rubocops/urls: allow plain HTTP mirrors

This commit is contained in:
Bo Anderson 2021-10-01 13:42:05 +01:00
parent d6eb9eca52
commit 629dbb7c59
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
2 changed files with 10 additions and 4 deletions

View File

@ -35,14 +35,14 @@ module RuboCop
# @param urls [Array] url/mirror method call nodes
# @param regex [Regexp] pattern to match URLs
def audit_urls(urls, regex)
urls.each do |url_node|
urls.each_with_index do |url_node, index|
url_string_node = parameters(url_node).first
url_string = string_content(url_string_node)
match_object = regex_match_group(url_string_node, regex)
next unless match_object
offending_node(url_string_node.parent)
yield match_object, url_string
yield match_object, url_string, index
end
end

View File

@ -83,8 +83,14 @@ module RuboCop
%r{^http://(?:[^/]*\.)?archive\.org},
%r{^http://(?:[^/]*\.)?freedesktop\.org},
%r{^http://(?:[^/]*\.)?mirrorservice\.org/}])
audit_urls(urls, http_to_https_patterns) do |_, url|
problem "Please use https:// for #{url}"
audit_urls(urls, http_to_https_patterns) do |_, url, index|
# It's fine to have a plain HTTP mirror further down the mirror list.
https_url = url.dup.insert(4, "s")
https_index = nil
audit_urls(urls, https_url) do |_, _, found_https_index|
https_index = found_https_index
end
problem "Please use https:// for #{url}" if !https_index || https_index > index
end
apache_mirror_pattern = %r{^https?://(?:[^/]*\.)?apache\.org/dyn/closer\.(?:cgi|lua)\?path=/?(.*)}i