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

CurlDownloadStrategy: Ignore invalid last-modified header values #17571

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Jun 26, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

  • Fixes Argument out of range, issue in resolve_url_basename_time_file_size #17556.
  • Some download locations return a non-standard formatting of date string for the Last-Modified header. This causes Time.parse to blow up. The user sees error: argument out of range.
  • In this commit we handle the error and return nil, which filter_map (equivalent to .map.compact) gets rid of and then time.last is as normal.

TODO: Figure out how to write some tests for this.


Before:

❯ brew install --cask ./olex2.rb                                                                                                        
Error: argument out of range
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.3/lib/ruby/3.3.0/time.rb:271:in `local'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.3/lib/ruby/3.3.0/time.rb:271:in `make_time'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.3/lib/ruby/3.3.0/time.rb:386:in `parse'
/opt/homebrew/Library/Homebrew/download_strategy.rb:523:in `block in resolve_url_basename_time_file_size'

After:

❯ brew install --cask ./olex2.rb
==> Downloading https://secure.olex2.org/olex2-distro/olex2-1.5.app.dmg
###########################

@issyl0 issyl0 force-pushed the ignore-last-modified-header-if-invalid branch 2 times, most recently from 3dd840b to ff77dc9 Compare June 26, 2024 18:58
- Some download locations return a non-standard formatting of date string for the `Last-Modified` header.
  This causes `Time.parse` to blow up. The user sees `error: argument out of range`.
- In this commit we handle the error and return nil, which `filter_map` (equivalent to `.map.compact`) gets rid of and then `time.last` is as normal.
- Fixes https://github.com/Homebrew/brew/issues/ 17556.
@issyl0 issyl0 force-pushed the ignore-last-modified-header-if-invalid branch from ff77dc9 to c850442 Compare June 26, 2024 19:00
@issyl0 issyl0 marked this pull request as ready for review June 26, 2024 19:17
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far, thanks @issyl0!

@MikeMcQuaid MikeMcQuaid merged commit 5f3af23 into master Jun 27, 2024
25 checks passed
@MikeMcQuaid MikeMcQuaid deleted the ignore-last-modified-header-if-invalid branch June 27, 2024 11:54
@MikeMcQuaid
Copy link
Member

Thanks again @issyl0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Argument out of range, issue in resolve_url_basename_time_file_size
2 participants