Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Escape strings in ruby-format specs using #dump instead of #to_s an…

…d %q. Issue #165
  • Loading branch information...
commit f6db093abe0840118808acfe843c7931fdcbb27f 1 parent a2498af
@drbrain drbrain authored
View
8 lib/rubygems/specification.rb
@@ -1690,11 +1690,11 @@ def ri_dir
def ruby_code(obj)
case obj
- when String then '%q{' + obj + '}'
+ when String then obj.dump
when Array then '[' + obj.map { |x| ruby_code x }.join(", ") + ']'
- when Gem::Version then obj.to_s.inspect
- when Date then '%q{' + obj.strftime('%Y-%m-%d') + '}'
- when Time then '%q{' + obj.strftime('%Y-%m-%d') + '}'
+ when Gem::Version then obj.to_s.dump
+ when Date then obj.strftime('%Y-%m-%d').dump
+ when Time then obj.strftime('%Y-%m-%d').dump
when Numeric then obj.inspect
when true, false, nil then obj.inspect
when Gem::Platform then "Gem::Platform.new(#{obj.to_a.inspect})"
View
2  test/rubygems/test_gem_commands_specification_command.rb
@@ -135,7 +135,7 @@ def test_execute_ruby
end
assert_match %r|Gem::Specification.new|, @ui.output
- assert_match %r|s.name = %q\{foo\}|, @ui.output
+ assert_match %r|s.name = "foo"|, @ui.output
assert_equal '', @ui.error
end
View
121 test/rubygems/test_gem_specification.rb
@@ -172,6 +172,51 @@ def test_self_load
assert_equal @a2, spec
end
+ def test_self_load_escape_curly
+ @a2.name = 'a};raise "improper escaping";%q{'
+
+ full_path = @a2.spec_file
+ write_file full_path do |io|
+ io.write @a2.to_ruby_for_cache
+ end
+
+ spec = Gem::Specification.load full_path
+
+ @a2.files.clear
+
+ assert_equal @a2, spec
+ end
+
+ def test_self_load_escape_interpolation
+ @a2.name = 'a#{raise %<improper escaping>}'
+
+ full_path = @a2.spec_file
+ write_file full_path do |io|
+ io.write @a2.to_ruby_for_cache
+ end
+
+ spec = Gem::Specification.load full_path
+
+ @a2.files.clear
+
+ assert_equal @a2, spec
+ end
+
+ def test_self_load_escape_quote
+ @a2.name = 'a";raise "improper escaping";"'
+
+ full_path = @a2.spec_file
+ write_file full_path do |io|
+ io.write @a2.to_ruby_for_cache
+ end
+
+ spec = Gem::Specification.load full_path
+
+ @a2.files.clear
+
+ assert_equal @a2, spec
+ end
+
def test_self_load_legacy_ruby
spec = Deprecate.skip_during do
eval LEGACY_RUBY_SPEC
@@ -785,19 +830,19 @@ def test_to_ruby
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{a}
- s.version = \"2\"
+ s.name = "a"
+ s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{A User}]
- s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
- s.description = %q{This is a test description}
- s.email = %q{example@example.com}
- s.files = [%q{lib/code.rb}]
- s.homepage = %q{http://example.com}
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{#{Gem::VERSION}}
- s.summary = %q{this is a summary}
+ s.authors = ["A User"]
+ s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
+ s.description = "This is a test description"
+ s.email = "example@example.com"
+ s.files = ["lib/code.rb"]
+ s.homepage = "http://example.com"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "#{Gem::VERSION}"
+ s.summary = "this is a summary"
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
@@ -832,18 +877,18 @@ def test_to_ruby_for_cache
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{a}
- s.version = \"2\"
+ s.name = "a"
+ s.version = "2"
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{A User}]
- s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
- s.description = %q{This is a test description}
- s.email = %q{example@example.com}
- s.homepage = %q{http://example.com}
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{#{Gem::VERSION}}
- s.summary = %q{this is a summary}
+ s.authors = ["A User"]
+ s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
+ s.description = "This is a test description"
+ s.email = "example@example.com"
+ s.homepage = "http://example.com"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "#{Gem::VERSION}"
+ s.summary = "this is a summary"
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
@@ -879,26 +924,26 @@ def test_to_ruby_fancy
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{a}
- s.version = \"1\"
+ s.name = "a"
+ s.version = "1"
s.platform = Gem::Platform.new(#{expected_platform})
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{A User}]
- s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
- s.description = %q{This is a test description}
- s.email = %q{example@example.com}
- s.executables = [%q{exec}]
- s.extensions = [%q{ext/a/extconf.rb}]
- s.files = [%q{lib/code.rb}, %q{test/suite.rb}, %q{bin/exec}, %q{ext/a/extconf.rb}]
- s.homepage = %q{http://example.com}
- s.licenses = [%q{MIT}]
- s.require_paths = [%q{lib}]
- s.requirements = [%q{A working computer}]
- s.rubyforge_project = %q{example}
- s.rubygems_version = %q{#{Gem::VERSION}}
- s.summary = %q{this is a summary}
- s.test_files = [%q{test/suite.rb}]
+ s.authors = ["A User"]
+ s.date = "#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}"
+ s.description = "This is a test description"
+ s.email = "example@example.com"
+ s.executables = ["exec"]
+ s.extensions = ["ext/a/extconf.rb"]
+ s.files = ["lib/code.rb", "test/suite.rb", "bin/exec", "ext/a/extconf.rb"]
+ s.homepage = "http://example.com"
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.requirements = ["A working computer"]
+ s.rubyforge_project = "example"
+ s.rubygems_version = "#{Gem::VERSION}"
+ s.summary = "this is a summary"
+ s.test_files = ["test/suite.rb"]
if s.respond_to? :specification_version then
s.specification_version = 3
Please sign in to comment.
Something went wrong with that request. Please try again.