diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-03-09 17:26:02 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2026-03-09 19:01:25 +0900 |
| commit | 1425c52227045fac17764b426a90d1b4ac369ba0 (patch) | |
| tree | 96b16602963546e72b80503467ed85f014213aef | |
| parent | 4da2b2d912b750d681b5a78ee8d4bba7a9015040 (diff) | |
Parse ISO8601 datetimes without Time.parse
| -rw-r--r-- | lib/rubygems/yaml_serializer.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/rubygems/yaml_serializer.rb b/lib/rubygems/yaml_serializer.rb index 28616cdfde..edc0133ce2 100644 --- a/lib/rubygems/yaml_serializer.rb +++ b/lib/rubygems/yaml_serializer.rb @@ -271,12 +271,16 @@ module Gem return Sequence.new if inner.empty? items = inner.split(/\s*,\s*/).reject(&:empty?).map {|e| Scalar.new(value: coerce(e)) } Sequence.new(items: items) - elsif /^\d{4}-\d{2}-\d{2}/.match?(val) - require "time" + elsif /\A\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}:\d{2})?/.match?(val) begin - Time.parse(val) + Time.new(val) rescue ArgumentError - val + # date-only format like "2024-06-15" is not supported by Time.new + if /\A(\d{4})-(\d{2})-(\d{2})\z/.match(val) + Time.utc($1.to_i, $2.to_i, $3.to_i) + else + val + end end elsif /^-?\d+$/.match?(val) val.to_i |
