Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livecheck: restrict POST hashes to symbol keys #19352

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def throttle(rate = T.unsafe(nil))
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)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/livecheck/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def self.from_url(url, livecheck_strategy: nil, regex_provided: false, block_pro
# @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)
Expand Down
10 changes: 0 additions & 10 deletions Library/Homebrew/test/livecheck/strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
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",
Expand Down Expand Up @@ -154,7 +146,6 @@
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.
Expand All @@ -163,7 +154,6 @@

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
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/test/livecheck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

let(:post_hash) do
{
"empty" => "",
"boolean" => "true",
"number" => "1",
"string" => "a + b = c",
empty: "",
boolean: "true",
number: "1",
string: "a + b = c",
}
end

Expand Down
4 changes: 2 additions & 2 deletions docs/Brew-Livecheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading