Skip to content

Commit 995e21e

Browse files
hsbtclaude
andcommitted
Parse compact index created_at strictly as ISO8601
Time.new accepts a bare year like "2026" and returns a local-time value instead of raising, so a malformed created_at was silently turned into a wrong timestamp. Use Time.iso8601 so anything that is not a real ISO8601 string falls back to nil. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8daf0d1 commit 995e21e

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/rubygems/resolver/api_specification.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def parse_created_at(value)
116116
value = value.first if value.is_a?(Array)
117117
return unless value.is_a?(String)
118118

119+
require "time"
119120
begin
120-
Time.new(value)
121+
Time.iso8601(value)
121122
rescue ArgumentError
122123
nil
123124
end

test/rubygems/test_gem_resolver_api_specification.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_initialize_created_at
4242

4343
spec = Gem::Resolver::APISpecification.new set, data
4444

45-
assert_equal Time.new("2026-06-05T10:30:45Z"), spec.created_at
45+
assert_equal Time.utc(2026, 6, 5, 10, 30, 45), spec.created_at
4646
end
4747

4848
def test_initialize_created_at_invalid
@@ -60,6 +60,21 @@ def test_initialize_created_at_invalid
6060
assert_nil spec.created_at
6161
end
6262

63+
def test_initialize_created_at_non_iso8601
64+
set = Gem::Resolver::APISet.new
65+
data = {
66+
name: "rails",
67+
number: "3.0.3",
68+
platform: "ruby",
69+
dependencies: [],
70+
requirements: { created_at: ["2026"] },
71+
}
72+
73+
spec = Gem::Resolver::APISpecification.new set, data
74+
75+
assert_nil spec.created_at
76+
end
77+
6378
def test_fetch_development_dependencies
6479
specs = spec_fetcher do |fetcher|
6580
fetcher.spec "rails", "3.0.3" do |s|

0 commit comments

Comments
 (0)