Merge pull request #19352 from Homebrew/livecheck/restrict-post-hashes-to-symbol-keys

livecheck: restrict POST hashes to symbol keys
This commit is contained in:
Mike McQuaid 2025-02-24 08:57:53 +00:00 committed by GitHub
commit b4648182ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 20 deletions

View File

@ -170,8 +170,8 @@ class Livecheck
params(
# URL to check for version information.
url: T.any(String, Symbol),
post_form: T.nilable(T::Hash[T.any(String, Symbol), String]),
post_json: T.nilable(T::Hash[T.any(String, Symbol), String]),
post_form: T.nilable(T::Hash[Symbol, String]),
post_json: T.nilable(T::Hash[Symbol, String]),
).returns(T.nilable(T.any(String, Symbol)))
}
def url(url = T.unsafe(nil), post_form: nil, post_json: nil)

View File

@ -172,8 +172,8 @@ module Homebrew
# @return [Array]
sig {
params(
post_form: T.nilable(T::Hash[T.any(String, Symbol), String]),
post_json: T.nilable(T::Hash[T.any(String, Symbol), String]),
post_form: T.nilable(T::Hash[Symbol, String]),
post_json: T.nilable(T::Hash[Symbol, String]),
).returns(T::Array[String])
}
def self.post_args(post_form: nil, post_json: nil)

View File

@ -9,14 +9,6 @@ RSpec.describe Homebrew::Livecheck::Strategy do
let(:redirection_url) { "https://brew.sh/redirection" }
let(:post_hash) do
{
"empty" => "",
"boolean" => "true",
"number" => "1",
"string" => "a + b = c",
}
end
let(:post_hash_symbol_keys) do
{
empty: "",
boolean: "true",
@ -154,7 +146,6 @@ RSpec.describe Homebrew::Livecheck::Strategy do
describe "::post_args" do
it "returns an array including `--data` and an encoded form data string" do
expect(strategy.post_args(post_form: post_hash)).to eq(["--data", form_string])
expect(strategy.post_args(post_form: post_hash_symbol_keys)).to eq(["--data", form_string])
# If both `post_form` and `post_json` are present, only `post_form` will
# be used.
@ -163,7 +154,6 @@ RSpec.describe Homebrew::Livecheck::Strategy do
it "returns an array including `--json` and a JSON string" do
expect(strategy.post_args(post_json: post_hash)).to eq(["--json", json_string])
expect(strategy.post_args(post_json: post_hash_symbol_keys)).to eq(["--json", json_string])
end
it "returns an empty array if `post_form` value is blank" do

View File

@ -29,10 +29,10 @@ RSpec.describe Livecheck do
let(:post_hash) do
{
"empty" => "",
"boolean" => "true",
"number" => "1",
"string" => "a + b = c",
empty: "",
boolean: "true",
number: "1",
string: "a + b = c",
}
end

View File

@ -119,8 +119,8 @@ Some checks require making a `POST` request and that can be accomplished by addi
```ruby
livecheck do
url "https://example.com/download.php", post_form: {
"Name" => "",
"E-mail" => "",
Name: "",
"E-mail": "",
}
regex(/href=.*?example[._-]v?(\d+(?:\.\d+)+)\.t/i)
end