Skip to content

Commit

Permalink
Perform Date => Time coercion on yaml loading. Fixes rubygems#266
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Mar 13, 2012
1 parent 47fd804 commit 10942d5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,9 @@ def yaml_initialize(tag, vals) # :nodoc:
instance_variable_set "@#{ivar}", val.untaint
end

# Force Date to go through the extra coerce logic in date=
self.date = @date

@original_platform = @platform # for backwards compatibility
self.platform = Gem::Platform.new @platform
end
Expand Down
51 changes: 51 additions & 0 deletions test/rubygems/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,57 @@ def test_self_from_yaml_cleans_up_defaultkey_from_newer_192
refute_match %r%DefaultKey%, new_spec.to_ruby
end

def test_self_from_yaml_cleans_up_Date_objects
yaml = <<-YAML
--- !ruby/object:Gem::Specification
rubygems_version: 0.8.1
specification_version: 1
name: diff-lcs
version: !ruby/object:Gem::Version
version: 1.1.2
date: 2004-10-20
summary: Provides a list of changes that represent the difference between two sequenced collections.
require_paths:
- lib
author: Austin Ziegler
email: diff-lcs@halostatue.ca
homepage: http://rubyforge.org/projects/ruwiki/
rubyforge_project: ruwiki
description: "Test"
bindir: bin
has_rdoc: true
required_ruby_version: !ruby/object:Gem::Version::Requirement
requirements:
-
- ">="
- !ruby/object:Gem::Version
version: 1.8.1
version:
platform: ruby
files:
- tests/00test.rb
rdoc_options:
- "--title"
- "Diff::LCS -- A Diff Algorithm"
- "--main"
- README
- "--line-numbers"
extra_rdoc_files:
- README
- ChangeLog
- Install
executables:
- ldiff
- htmldiff
extensions: []
requirements: []
dependencies: []
YAML

new_spec = Gem::Specification.from_yaml yaml

assert_kind_of Time, new_spec.date
end

def test_self_load
full_path = @a2.spec_file
Expand Down

0 comments on commit 10942d5

Please sign in to comment.