Permalink
Browse files

UTF-8 fixes for .gemspec files

git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@1868 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
1 parent 50eb9b2 commit 58df2e6c6312eb4426c66cfae3602ff24f0cab4e @drbrain drbrain committed Sep 11, 2008
Showing with 70 additions and 5 deletions.
  1. +3 −0 ChangeLog
  2. +7 −1 lib/rubygems/source_index.rb
  3. +2 −0 lib/rubygems/specification.rb
  4. +48 −0 test/test_gem_source_index.rb
  5. +10 −4 test/test_gem_specification.rb
View
@@ -8,6 +8,9 @@
variables and gemrc in `gem help env`.
* lib/rubygems.rb: Warn when executing Gem::manage_gems.
* lib/rubygems/doc_manager.rb: Have RubyGems update the ri cache.
+ * lib/rubygems/source_index.rb: Ensure specs are read as UTF-8.
+ * lib/rubygems/specification.rb: Add magic comment to .gemspec files
+ so they are read in as UTF-8.
2008-08-22 Luis Lavena <luislavena@gmail.com>
@@ -80,8 +80,14 @@ def from_gems_in(*spec_dirs)
def load_specification(file_name)
begin
- spec_code = File.read(file_name).untaint
+ spec_code = if RUBY_VERSION < '1.9' then
+ File.read file_name
+ else
+ File.read file_name, :encoding => 'UTF-8'
+ end.untaint
+
gemspec = eval spec_code, binding, file_name
+
if gemspec.is_a?(Gem::Specification)
gemspec.loaded_from = file_name
return gemspec
@@ -711,6 +711,8 @@ def yaml_initialize(tag, vals) # :nodoc:
def to_ruby
mark_version
result = []
+ result << "# -*- encoding: utf-8 -*-"
+ result << nil
result << "Gem::Specification.new do |s|"
result << " s.name = #{ruby_code name}"
@@ -64,6 +64,54 @@ def test_self_load_specification
assert_equal a1.author, spec.author
end
+ def test_self_load_specification_utf_8
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.rm_r spec_dir
+
+ FileUtils.mkdir_p spec_dir
+
+ spec_file = File.join spec_dir, "utf-8.gemspec"
+ spec_data = <<-SPEC
+Gem::Specification.new do |s|
+ s.name = %q{utf}
+ s.version = "8"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0")
+ s.authors = ["\317\200"]
+ s.date = %q{2008-09-10}
+ s.description = %q{This is a test description}
+ s.email = %q{example@example.com}
+ s.has_rdoc = true
+ s.homepage = %q{http://example.com}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.2.0}
+ s.summary = %q{this is a summary}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+ SPEC
+
+ spec_data.force_encoding 'UTF-8'
+
+ File.open spec_file, 'w' do |io| io.write spec_data end
+
+ spec = Gem::SourceIndex.load_specification spec_file
+
+ pi = "\317\200"
+ pi.force_encoding 'UTF-8' if pi.respond_to? :force_encoding
+
+ assert_equal pi, spec.author
+ end if Gem.ruby_version > Gem::Version.new('1.9')
+
def test_self_load_specification_exception
spec_dir = File.join @gemhome, 'specifications'
@@ -634,7 +634,10 @@ def test_to_ruby
ruby_code = @a2.to_ruby
- expected = "Gem::Specification.new do |s|
+ expected = <<-SPEC
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
s.name = %q{a}
s.version = \"2\"
@@ -663,7 +666,7 @@ def test_to_ruby
s.add_dependency(%q<b>, [\"= 1\"])
end
end
-"
+ SPEC
assert_equal expected, ruby_code
@@ -679,7 +682,10 @@ def test_to_ruby_fancy
local = Gem::Platform.local
expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]"
- expected = "Gem::Specification.new do |s|
+ expected = <<-SPEC
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
s.name = %q{a}
s.version = \"1\"
s.platform = Gem::Platform.new(#{expected_platform})
@@ -721,7 +727,7 @@ def test_to_ruby_fancy
s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
end
end
-"
+ SPEC
assert_equal expected, ruby_code

0 comments on commit 58df2e6

Please sign in to comment.