Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
321d93c
Implement name field for Gem::Specification in YAMLSerializer
hsbt Feb 25, 2026
9c92977
Implement version field for Gem::Specification in YAMLSerializer
hsbt Feb 25, 2026
e680694
Implement authors field for Gem::Specification in YAMLSerializer
hsbt Feb 25, 2026
384d093
Implement summary field for Gem::Specification in YAMLSerializer
hsbt Feb 25, 2026
0694b0f
Implement description field for Gem::Specification in YAMLSerializer
hsbt Feb 25, 2026
bb280a9
Use YAMLSerializer in Gem.load_yaml
hsbt Feb 25, 2026
91afde8
Use YAMLSerializer in Gem::SafeYAML
hsbt Feb 25, 2026
7a66572
Use YAMLSerializer.dump in Gem::Specification#to_yaml
hsbt Feb 25, 2026
014e41c
Remove direct Psych dependencies in Gem::Package
hsbt Feb 25, 2026
36bb34c
Use YAMLSerializer in Gem::TestCase#load_yaml
hsbt Feb 25, 2026
edd3c9f
Replace Psych.dump with Gem::YAMLSerializer.dump in test_gem_package.rb
hsbt Feb 25, 2026
db0045a
Implement robust pure-Ruby YAML serializer and parser for gemspecs an…
hsbt Feb 25, 2026
6ba1dec
Enhance YAML serializer to handle multiline strings, add Gem::Depende…
hsbt Feb 25, 2026
3a10e55
Use Gem::YAMLSerializer for YAML output, parse cargo metadata with JS…
hsbt Feb 25, 2026
b835eee
Refactor YAML parsing to handle lone '-' lists, fix recursion/indent …
hsbt Feb 25, 2026
62b49a7
Complete pure-Ruby YAML implementation and fix related test failures
hsbt Feb 25, 2026
9af2f76
bin/rubocop -A
hsbt Feb 25, 2026
0d55746
Replace String.new concatenations with string literals and joined par…
hsbt Feb 25, 2026
5a43b73
Remove lib/rubygems/psych_tree.rb custom NoAliasYAMLTree that disable…
hsbt Feb 25, 2026
cf4c2ac
Use Gem::SafeYAML::PERMITTED_CLASSES
hsbt Feb 25, 2026
b91658d
Use Gem::SafeYAML::PERMITTED_SYMBOLS
hsbt Feb 25, 2026
6b61afe
Use aliases_enabled
hsbt Feb 25, 2026
f29ab19
Don't need to use PERMITTED_CLASSES and PERMITTED_SYMBOLS for SafeYAM…
hsbt Feb 25, 2026
4678d73
bin/rubocop -a
hsbt Feb 25, 2026
0c21d9b
Ensure specification_version is an Integer during YAML deserializatio…
hsbt Feb 25, 2026
67f238a
Fix YAMLSerializer parsing for empty array items and restrict specifi…
hsbt Feb 25, 2026
d223a07
Restrict YAML deserialization by passing permitted_classes: [] and re…
hsbt Feb 25, 2026
9110f9f
Add YAML anchor/alias support and parsing robustness to YAMLSerialize…
hsbt Feb 25, 2026
755fbc6
Normalize YAML-serialized spec fields into arrays to ensure rdoc_opti…
hsbt Feb 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ lib/rubygems/package/tar_writer.rb
lib/rubygems/package_task.rb
lib/rubygems/path_support.rb
lib/rubygems/platform.rb
lib/rubygems/psych_tree.rb
lib/rubygems/query_utils.rb
lib/rubygems/rdoc.rb
lib/rubygems/remote_fetcher.rb
Expand Down
4 changes: 1 addition & 3 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,7 @@ def self.add_to_load_path(*paths)
def self.load_yaml
return if @yaml_loaded

require "psych"
require_relative "rubygems/psych_tree"

require_relative "rubygems/yaml_serializer"
require_relative "rubygems/safe_yaml"

@yaml_loaded = true
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/specification_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def execute
say case options[:format]
when :ruby then s.to_ruby
when :marshal then Marshal.dump s
else s.to_yaml
else Gem::YAMLSerializer.dump(s)
end

say "\n"
Expand Down
6 changes: 4 additions & 2 deletions lib/rubygems/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ def self.dump_with_rubygems_yaml(content)
def self.load_with_rubygems_config_hash(yaml)
require_relative "yaml_serializer"

content = Gem::YAMLSerializer.load(yaml)
content = Gem::YAMLSerializer.load(yaml, permitted_classes: [])
return {} unless content.is_a?(Hash)

deep_transform_config_keys!(content)
end

Expand Down Expand Up @@ -597,7 +599,7 @@ def self.deep_transform_config_keys!(config)
else
v
end
elsif v.empty?
elsif v.respond_to?(:empty?) && v.empty?
nil
elsif v.is_a?(Hash)
deep_transform_config_keys!(v)
Expand Down
7 changes: 3 additions & 4 deletions lib/rubygems/ext/cargo_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ def cargo_crate_name(cargo_dir, manifest_path, results)
raise Gem::InstallError, "cargo metadata failed#{exit_reason}"
end

# cargo metadata output is specified as json, but with the
# --format-version 1 option the output is compatible with YAML, so we can
# avoid the json dependency
metadata = Gem::SafeYAML.safe_load(output)
# cargo metadata output is specified as json
require "json"
metadata = JSON.parse(output)
package = metadata["packages"].find {|pkg| normalize_path(pkg["manifest_path"]) == manifest_path }
unless package
found = metadata["packages"].map {|md| "#{md["name"]} at #{md["manifest_path"]}" }
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def add_checksums(tar)

tar.add_file_signed "checksums.yaml.gz", 0o444, @signer do |io|
gzip_to io do |gz_io|
Psych.dump checksums_by_algorithm, gz_io
gz_io.write Gem::YAMLSerializer.dump(checksums_by_algorithm)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/package/old.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def spec

begin
@spec = Gem::Specification.from_yaml yaml
rescue Psych::SyntaxError
rescue StandardError
raise Gem::Exception, "Failed to parse gem specification out of gem file"
end
rescue ArgumentError
Expand Down
37 changes: 0 additions & 37 deletions lib/rubygems/psych_tree.rb

This file was deleted.

12 changes: 10 additions & 2 deletions lib/rubygems/safe_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ def self.aliases_enabled? # :nodoc:
end

def self.safe_load(input)
::Psych.safe_load(input, permitted_classes: PERMITTED_CLASSES, permitted_symbols: PERMITTED_SYMBOLS, aliases: @aliases_enabled)
Gem::YAMLSerializer.load(
input,
permitted_classes: PERMITTED_CLASSES,
permitted_symbols: PERMITTED_SYMBOLS,
aliases: aliases_enabled?
)
end

def self.load(input)
::Psych.safe_load(input, permitted_classes: [::Symbol])
Gem::YAMLSerializer.load(
input,
permitted_classes: [::Symbol]
)
end
end
end
20 changes: 1 addition & 19 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2454,25 +2454,7 @@ def to_spec

def to_yaml(opts = {}) # :nodoc:
Gem.load_yaml

# Because the user can switch the YAML engine behind our
# back, we have to check again here to make sure that our
# psych code was properly loaded, and load it if not.
unless Gem.const_defined?(:NoAliasYAMLTree)
require_relative "psych_tree"
end

builder = Gem::NoAliasYAMLTree.create
builder << self
ast = builder.tree

require "stringio"
io = StringIO.new
io.set_encoding Encoding::UTF_8

Psych::Visitors::Emitter.new(io).accept(ast)

io.string.gsub(/ !!null \n/, " \n")
Gem::YAMLSerializer.dump(self)
end

##
Expand Down
Loading
Loading