api: use freeze option for JSON parsing

This commit is contained in:
Bo Anderson 2024-01-09 18:07:08 +00:00
parent 11e4b66dcf
commit 1c3c64a743
No known key found for this signature in database
4 changed files with 7 additions and 7 deletions

View File

@ -30,7 +30,7 @@ module Homebrew
end
raise ArgumentError, "No file found at #{Tty.underline}#{api_url}#{Tty.reset}" unless output.success?
cache[endpoint] = JSON.parse(output.stdout)
cache[endpoint] = JSON.parse(output.stdout, freeze: true)
rescue JSON::ParserError
raise ArgumentError, "Invalid JSON file: #{Tty.underline}#{api_url}#{Tty.reset}"
end
@ -96,7 +96,7 @@ module Homebrew
mtime = insecure_download ? Time.new(1970, 1, 1) : Time.now
FileUtils.touch(target, mtime: mtime) unless skip_download
JSON.parse(target.read)
JSON.parse(target.read, freeze: true)
rescue JSON::ParserError
target.unlink
retry_count += 1
@ -170,7 +170,7 @@ module Homebrew
return false, "signature mismatch"
end
[true, JSON.parse(json_data["payload"])]
[true, JSON.parse(json_data["payload"], freeze: true)]
end
sig { params(path: Pathname).returns(T.nilable(Tap)) }

View File

@ -47,13 +47,13 @@ module Homebrew
cache["renames"] = {}
cache["casks"] = json_casks.to_h do |json_cask|
token = json_cask.delete("token")
token = json_cask["token"]
json_cask.fetch("old_tokens", []).each do |old_token|
cache["renames"][old_token] = token
end
[token, json_cask]
[token, json_cask.except("token")]
end
updated

View File

@ -349,7 +349,7 @@ module Cask
def to_hash_with_variations
if loaded_from_api? && !Homebrew::EnvConfig.no_install_from_api?
return api_to_local_hash(Homebrew::API::Cask.all_casks[token])
return api_to_local_hash(Homebrew::API::Cask.all_casks[token].dup)
end
hash = to_h

View File

@ -232,7 +232,7 @@ module Formulary
end
dep_json["uses_from_macos"]&.each_with_index do |dep, index|
bounds = dep_json.fetch("uses_from_macos_bounds", [])[index] || {}
bounds = dep_json.fetch("uses_from_macos_bounds", [])[index].dup || {}
bounds.deep_transform_keys!(&:to_sym)
bounds.deep_transform_values! { |val| val.is_a?(String) ? val.to_sym : val }