diff --git a/Library/Homebrew/rubocops/shared/url_helper.rb b/Library/Homebrew/rubocops/shared/url_helper.rb index 1d5e6a32ff..0a49816f13 100644 --- a/Library/Homebrew/rubocops/shared/url_helper.rb +++ b/Library/Homebrew/rubocops/shared/url_helper.rb @@ -35,6 +35,12 @@ module RuboCop def audit_url(type, urls, mirrors, livecheck_url: false) @type = type + # URLs must be ASCII; IDNs must be punycode + ascii_pattern = /[^\p{ASCII}]+/ + audit_urls(urls, ascii_pattern) do |_, url| + problem "Please use the ASCII (Punycode encoded host, URL-encoded path and query) version of #{url}." + end + # GNU URLs; doesn't apply to mirrors gnu_pattern = %r{^(?:https?|ftp)://ftpmirror\.gnu\.org/(.*)} audit_urls(urls, gnu_pattern) do |match, url| diff --git a/Library/Homebrew/test/rubocops/urls_spec.rb b/Library/Homebrew/test/rubocops/urls_spec.rb index 80bf49199a..fab6d84ada 100644 --- a/Library/Homebrew/test/rubocops/urls_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_spec.rb @@ -177,6 +177,14 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Urls do "url" => "svn+http://brew.sh/foo/bar", "msg" => "Use of the svn+http:// scheme is deprecated, pass `:using => :svn` instead", "col" => 2, + }, { + "url" => "https://🫠.sh/foo/bar", + "msg" => "Please use the ASCII (Punycode encoded host, URL-encoded path and query) version of https://🫠.sh/foo/bar.", + "col" => 2, + }, { + "url" => "https://ßrew.sh/foo/bar", + "msg" => "Please use the ASCII (Punycode encoded host, URL-encoded path and query) version of https://ßrew.sh/foo/bar.", + "col" => 2, }] end