Skip to content

Commit dffb5a3

Browse files
Merge pull request #8355 from rubygems/deivid-rodriguez/fix-platform-serialization
Fix serialized metadata including an empty `@original_platform` attribute (cherry picked from commit 8ecfd0d)
1 parent fa5fb13 commit dffb5a3

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/rubygems/specification.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,16 +1817,8 @@ def doc_dir(type = nil)
18171817
def encode_with(coder) # :nodoc:
18181818
coder.add "name", @name
18191819
coder.add "version", @version
1820-
platform = case @new_platform
1821-
when nil, "" then
1822-
"ruby"
1823-
when String then
1824-
@new_platform
1825-
else
1826-
@new_platform.to_s
1827-
end
1828-
coder.add "platform", platform
1829-
coder.add "original_platform", @original_platform.to_s if platform != @original_platform.to_s
1820+
coder.add "platform", platform.to_s
1821+
coder.add "original_platform", original_platform.to_s if platform.to_s != original_platform.to_s
18301822

18311823
attributes = @@attributes.map(&:to_s) - %w[name version platform]
18321824
attributes.each do |name|

test/rubygems/test_gem_specification.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,31 @@ def test_to_yaml_fancy
24922492
assert_equal @a1, same_spec
24932493
end
24942494

2495-
def test_to_yaml_platform_empty_string
2495+
def test_to_yaml_platform
2496+
yaml_str = @a1.to_yaml
2497+
2498+
assert_match(/^platform: ruby$/, yaml_str)
2499+
refute_match(/^original_platform: /, yaml_str)
2500+
end
2501+
2502+
def test_to_yaml_platform_no_specific_platform
2503+
a = Gem::Specification.new do |s|
2504+
s.name = "a"
2505+
s.version = "1.0"
2506+
s.author = "A User"
2507+
s.email = "[email protected]"
2508+
s.homepage = "http://example.com"
2509+
s.summary = "this is a summary"
2510+
s.description = "This is a test description"
2511+
end
2512+
2513+
yaml_str = a.to_yaml
2514+
2515+
assert_match(/^platform: ruby$/, yaml_str)
2516+
refute_match(/^original_platform: /, yaml_str)
2517+
end
2518+
2519+
def test_to_yaml_platform_original_platform_empty_string
24962520
@a1.instance_variable_set :@original_platform, ""
24972521

24982522
assert_match(/^platform: ruby$/, @a1.to_yaml)
@@ -2510,7 +2534,7 @@ def test_to_yaml_platform_legacy
25102534
assert_equal "powerpc-darwin7.9.0", same_spec.original_platform
25112535
end
25122536

2513-
def test_to_yaml_platform_nil
2537+
def test_to_yaml_platform_original_platform_nil
25142538
@a1.instance_variable_set :@original_platform, nil
25152539

25162540
assert_match(/^platform: ruby$/, @a1.to_yaml)

0 commit comments

Comments
 (0)