Skip to content

Commit

Permalink
- Syck has a parse error on (good) times output from Psych. (dazuma, …
Browse files Browse the repository at this point in the history
…et al)
  • Loading branch information
zenspider committed May 19, 2011
1 parent 196ac05 commit 21cccd5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ def self.non_nil_attributes
def self.normalize_yaml_input(input)
result = input.respond_to?(:read) ? input.read : input
result = "--- " + result unless result =~ /\A--- /
result.gsub(/ !!null \n/, " \n")
result.gsub!(/ !!null \n/, " \n")
# date: 2011-04-26 00:00:00.000000000Z
# date: 2011-04-26 00:00:00.000000000 Z
result.gsub!(/^(date: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+?)Z/, '\1 Z')
result
end

##
Expand Down
32 changes: 32 additions & 0 deletions test/rubygems/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ def test_self__load_future
assert_equal @current_version, new_spec.specification_version
end

def test_self_from_yaml_syck_bug
# This is equivalent to (and totally valid) psych 1.0 output and
# causes parse errors on syck.
yaml = @a1.to_yaml
yaml.sub!(/^date:.*/, "date: 2011-04-26 00:00:00.000000000Z")

new_spec = with_syck do
Gem::Specification.from_yaml yaml
end

assert_kind_of Time, @a1.date
assert_kind_of Time, new_spec.date
end

def test_self_load
full_path = @a2.spec_file
write_file full_path do |io|
Expand Down Expand Up @@ -1386,4 +1400,22 @@ def util_setup_validate
end
end
end

def with_syck
begin
require "yaml"
old_engine = YAML::ENGINE.yamler
YAML::ENGINE.yamler = 'syck'
rescue NameError
# probably on 1.8, ignore
end

yield
ensure
begin
YAML::ENGINE.yamler = old_engine
rescue NameError
# ignore
end
end
end

0 comments on commit 21cccd5

Please sign in to comment.