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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Incorrect Dates on some Gem::Specification #6859

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rubygems.rb
Expand Up @@ -1126,8 +1126,8 @@ def self.source_date_epoch_string

specified_epoch = ENV["SOURCE_DATE_EPOCH"]

# If it's empty or just whitespace, treat it like it wasn't set at all.
specified_epoch = nil if !specified_epoch.nil? && specified_epoch.strip.empty?
# If it's empty, just whitespace, or a unique placeholder, treat it like it wasn't set at all.
specified_epoch = nil if !specified_epoch.nil? && (specified_epoch.strip.empty? || specified_epoch === "315532800")

epoch = specified_epoch || @default_source_date_epoch

Expand Down
14 changes: 14 additions & 0 deletions test/rubygems/test_gem_package.rb
Expand Up @@ -140,6 +140,20 @@ def test_build_time_without_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = epoch
end

def test_build_time_ignores_invalid_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "315532800"
Copy link
Contributor

Choose a reason for hiding this comment

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

This environment variable should be restored after this test, like the other related tests.


spec = Gem::Specification.new "build", "1"
spec.summary = "build"
spec.authors = "build"
spec.files = ["lib/code.rb"]
spec.rubygems_version = Gem::Version.new "0"

package = Gem::Package.new spec.file_name

refute_equal Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc, package.build_time
end

def test_add_files
spec = Gem::Specification.new
spec.files = %w[lib/code.rb lib/empty]
Expand Down