Merge pull request #20026 from abitrolly/non-archive-fix

create: fix archive check if HTML starts with spaces
This commit is contained in:
Mike McQuaid 2025-05-30 16:49:09 +00:00 committed by GitHub
commit bdbd80671a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,7 +84,10 @@ module Homebrew
r.owner = self
filepath = r.fetch
html_doctype_prefix = "<!doctype html"
if File.read(filepath, html_doctype_prefix.length).downcase.start_with?(html_doctype_prefix)
# Number of bytes to read from file start to ensure it is not HTML.
# HTML may start with arbitrary number of whitespace lines.
bytes_to_read = 100
if File.read(filepath, bytes_to_read).strip.downcase.start_with?(html_doctype_prefix)
raise "Downloaded URL is not archive"
end