Skip to content
This repository
Browse code

- Syck has a parse error on (good) times output from Psych. (dazuma, …

…et al)
  • Loading branch information...
commit 21cccd55b823848c5e941093a615b0fdd6cd8bc7 1 parent 196ac05
Ryan Davis authored May 18, 2011
6  lib/rubygems/specification.rb
@@ -561,7 +561,11 @@ def self.non_nil_attributes
561 561
   def self.normalize_yaml_input(input)
562 562
     result = input.respond_to?(:read) ? input.read : input
563 563
     result = "--- " + result unless result =~ /\A--- /
564  
-    result.gsub(/ !!null \n/, " \n")
  564
+    result.gsub!(/ !!null \n/, " \n")
  565
+    # date: 2011-04-26 00:00:00.000000000Z
  566
+    # date: 2011-04-26 00:00:00.000000000 Z
  567
+    result.gsub!(/^(date: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+?)Z/, '\1 Z')
  568
+    result
565 569
   end
566 570
 
567 571
   ##
32  test/rubygems/test_gem_specification.rb
@@ -114,6 +114,20 @@ def test_self__load_future
114 114
     assert_equal @current_version, new_spec.specification_version
115 115
   end
116 116
 
  117
+  def test_self_from_yaml_syck_bug
  118
+    # This is equivalent to (and totally valid) psych 1.0 output and
  119
+    # causes parse errors on syck.
  120
+    yaml = @a1.to_yaml
  121
+    yaml.sub!(/^date:.*/, "date: 2011-04-26 00:00:00.000000000Z")
  122
+
  123
+    new_spec = with_syck do
  124
+      Gem::Specification.from_yaml yaml
  125
+    end
  126
+
  127
+    assert_kind_of Time, @a1.date
  128
+    assert_kind_of Time, new_spec.date
  129
+  end
  130
+
117 131
   def test_self_load
118 132
     full_path = @a2.spec_file
119 133
     write_file full_path do |io|
@@ -1386,4 +1400,22 @@ def util_setup_validate
1386 1400
       end
1387 1401
     end
1388 1402
   end
  1403
+
  1404
+  def with_syck
  1405
+    begin
  1406
+      require "yaml"
  1407
+      old_engine = YAML::ENGINE.yamler
  1408
+      YAML::ENGINE.yamler = 'syck'
  1409
+    rescue NameError
  1410
+      # probably on 1.8, ignore
  1411
+    end
  1412
+
  1413
+    yield
  1414
+  ensure
  1415
+    begin
  1416
+      YAML::ENGINE.yamler = old_engine
  1417
+    rescue NameError
  1418
+      # ignore
  1419
+    end
  1420
+  end
1389 1421
 end

0 notes on commit 21cccd5

Please sign in to comment.
Something went wrong with that request. Please try again.