$NetBSD: patch-an,v 1.3 2011/09/04 17:02:39 taca Exp $

* Make sure to load YAML before use it.  When should YAML be loaded?
* Relax to allow some attribute could be nil.
* Complete "http://" to homepage attribute if it isn't begin with it.
* Fix handling of String in ruby_code().  (From rubygem's repository,
  6ff4e0eed52ef066fe33.)

--- lib/rubygems/specification.rb.orig	2010-04-22 08:24:42.000000000 +0000
+++ lib/rubygems/specification.rb
@@ -107,6 +107,10 @@ class Gem::Specification
 
   @@default_value = {}
 
+  # under pkgsrc environment
+  @@pkgsrc_nil_attributes =
+    [:authors, :cert_chain, :executables, :extensions, :extra_rdoc_files, :licenses, :required_rubygems_version, :test_files]
+
   ##
   # Names of all specification attributes
 
@@ -476,6 +480,7 @@ class Gem::Specification
   # 'input' can be anything that YAML.load() accepts: String or IO.
 
   def self.from_yaml(input)
+    require 'yaml'
     input = normalize_yaml_input input
     spec = YAML.load input
 
@@ -819,6 +824,23 @@ class Gem::Specification
             "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
     end
 
+    @@pkgsrc_nil_attributes.each do |name|
+      val = instance_variable_get("@#{name}")
+      if val.nil?
+        case name
+        when :required_rubygems_version
+          val = Gem::Requirement.default
+        else
+          val = []
+        end
+        instance_variable_set("@#{name}", val)
+      end
+      if name == :authors and val.empty?
+        val = ['not specified']
+        instance_variable_set("@#{name}", val)
+      end
+    end
+
     @@required_attributes.each do |symbol|
       unless self.send symbol then
         raise Gem::InvalidSpecificationException,
@@ -901,10 +923,15 @@ class Gem::Specification
             '"FIXME" or "TODO" is not a summary'
     end
 
-    if homepage and not homepage.empty? and
-       homepage !~ /\A[a-z][a-z\d+.-]*:/i then
-      raise Gem::InvalidSpecificationException,
-            "\"#{homepage}\" is not a URI"
+    if homepage and not homepage.empty?
+      if @homepage =~ /\A[a-z][a-z\d+.-]*/i and
+          @homepage !~ /\A[a-z][a-z\d+.-]*:/i
+        @homepage = "http://" + @homepage
+      end
+      if homepage !~ /\A[a-z][a-z\d+.-]*:/i then
+        raise Gem::InvalidSpecificationException,
+              "\"#{homepage}\" is not a URI"
+      end
     end
 
     # Warnings
@@ -1038,7 +1065,7 @@ class Gem::Specification
 
   def ruby_code(obj)
     case obj
-    when String            then '%q{' + obj + '}'
+    when String            then obj.inspect
     when Array             then obj.inspect
     when Gem::Version      then obj.to_s.inspect
     when Date              then '%q{' + obj.strftime('%Y-%m-%d') + '}'
