From 4d7919992acef586bc11bf8af7098538d180dd9e Mon Sep 17 00:00:00 2001 From: SHIBATA Hiroshi Date: Thu, 17 May 2018 15:40:31 +0900 Subject: [PATCH 1/3] Removed self-hosted YAML Serializer, It is not compatible YAML spec in standard library of Ruby --- lib/bundler/plugin/index.rb | 8 +- lib/bundler/settings.rb | 8 +- spec/bundler/yaml_serializer_spec.rb | 194 --------------------------- 3 files changed, 8 insertions(+), 202 deletions(-) delete mode 100644 spec/bundler/yaml_serializer_spec.rb diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 2d70a046bb6..46189e871a9 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -139,8 +139,8 @@ def load_index(index_file, global = false) data = index_f.read - require_relative "../yaml_serializer" - index = YAMLSerializer.load(data) + require_relative "psyched_yaml" + index = YAML.load(data) @commands.merge!(index["commands"]) @hooks.merge!(index["hooks"]) @@ -162,10 +162,10 @@ def save_index "sources" => @sources, } - require_relative "../yaml_serializer" + require_relative "psyched_yaml" SharedHelpers.filesystem_access(index_file) do |index_f| FileUtils.mkdir_p(index_f.dirname) - File.open(index_f, "w") {|f| f.puts YAMLSerializer.dump(index) } + File.open(index_f, "w") {|f| f.puts YAML.dump(index) } end end end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 166e494f0e4..203e5e8f7b1 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -352,8 +352,8 @@ def set_key(raw_key, value, hash, file) return unless file SharedHelpers.filesystem_access(file) do |p| FileUtils.mkdir_p(p.dirname) - require_relative "yaml_serializer" - p.open("w") {|f| f.write(YAMLSerializer.dump(hash)) } + require_relative "psyched_yaml" + p.open("w") {|f| f.write(YAML.dump(hash)) } end end @@ -392,8 +392,8 @@ def load_config(config_file) SharedHelpers.filesystem_access(config_file, :read) do |file| valid_file = file.exist? && !file.size.zero? return {} unless valid_file - require_relative "yaml_serializer" - YAMLSerializer.load file.read + require_relative "psyched_yaml" + YAML.load file.read end end diff --git a/spec/bundler/yaml_serializer_spec.rb b/spec/bundler/yaml_serializer_spec.rb deleted file mode 100644 index 1241c74bbfd..00000000000 --- a/spec/bundler/yaml_serializer_spec.rb +++ /dev/null @@ -1,194 +0,0 @@ -# frozen_string_literal: true - -require "bundler/yaml_serializer" - -RSpec.describe Bundler::YAMLSerializer do - subject(:serializer) { Bundler::YAMLSerializer } - - describe "#dump" do - it "works for simple hash" do - hash = { "Q" => "Where does Thursday come before Wednesday? In the dictionary. :P" } - - expected = strip_whitespace <<-YAML - --- - Q: "Where does Thursday come before Wednesday? In the dictionary. :P" - YAML - - expect(serializer.dump(hash)).to eq(expected) - end - - it "handles nested hash" do - hash = { - "nice-one" => { - "read_ahead" => "All generalizations are false, including this one", - }, - } - - expected = strip_whitespace <<-YAML - --- - nice-one: - read_ahead: "All generalizations are false, including this one" - YAML - - expect(serializer.dump(hash)).to eq(expected) - end - - it "array inside an hash" do - hash = { - "nested_hash" => { - "contains_array" => [ - "Jack and Jill went up the hill", - "To fetch a pail of water.", - "Jack fell down and broke his crown,", - "And Jill came tumbling after.", - ], - }, - } - - expected = strip_whitespace <<-YAML - --- - nested_hash: - contains_array: - - "Jack and Jill went up the hill" - - "To fetch a pail of water." - - "Jack fell down and broke his crown," - - "And Jill came tumbling after." - YAML - - expect(serializer.dump(hash)).to eq(expected) - end - end - - describe "#load" do - it "works for simple hash" do - yaml = strip_whitespace <<-YAML - --- - Jon: "Air is free dude!" - Jack: "Yes.. until you buy a bag of chips!" - YAML - - hash = { - "Jon" => "Air is free dude!", - "Jack" => "Yes.. until you buy a bag of chips!", - } - - expect(serializer.load(yaml)).to eq(hash) - end - - it "works for nested hash" do - yaml = strip_whitespace <<-YAML - --- - baa: - baa: "black sheep" - have: "you any wool?" - yes: "merry have I" - three: "bags full" - YAML - - hash = { - "baa" => { - "baa" => "black sheep", - "have" => "you any wool?", - "yes" => "merry have I", - }, - "three" => "bags full", - } - - expect(serializer.load(yaml)).to eq(hash) - end - - it "handles colon in key/value" do - yaml = strip_whitespace <<-YAML - BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/: http://rubygems-mirror.org - YAML - - expect(serializer.load(yaml)).to eq("BUNDLE_MIRROR__HTTPS://RUBYGEMS__ORG/" => "http://rubygems-mirror.org") - end - - it "handles arrays inside hashes" do - yaml = strip_whitespace <<-YAML - --- - nested_hash: - contains_array: - - "Why shouldn't you write with a broken pencil?" - - "Because it's pointless!" - YAML - - hash = { - "nested_hash" => { - "contains_array" => [ - "Why shouldn't you write with a broken pencil?", - "Because it's pointless!", - ], - }, - } - - expect(serializer.load(yaml)).to eq(hash) - end - - it "handles windows-style CRLF line endings" do - yaml = strip_whitespace(<<-YAML).gsub("\n", "\r\n") - --- - nested_hash: - contains_array: - - "Why shouldn't you write with a broken pencil?" - - "Because it's pointless!" - - oh so silly - YAML - - hash = { - "nested_hash" => { - "contains_array" => [ - "Why shouldn't you write with a broken pencil?", - "Because it's pointless!", - "oh so silly", - ], - }, - } - - expect(serializer.load(yaml)).to eq(hash) - end - end - - describe "against yaml lib" do - let(:hash) do - { - "a_joke" => { - "my-stand" => "I can totally keep secrets", - "but" => "The people I tell them to can't :P", - "wouldn't it be funny if this string were empty?" => "", - }, - "more" => { - "first" => [ - "Can a kangaroo jump higher than a house?", - "Of course, a house doesn't jump at all.", - ], - "second" => [ - "What did the sea say to the sand?", - "Nothing, it simply waved.", - ], - "array with empty string" => [""], - }, - "sales" => { - "item" => "A Parachute", - "description" => "Only used once, never opened.", - }, - "one-more" => "I'd tell you a chemistry joke but I know I wouldn't get a reaction.", - } - end - - context "#load" do - it "retrieves the original hash" do - require "yaml" - expect(serializer.load(YAML.dump(hash))).to eq(hash) - end - end - - context "#dump" do - it "retrieves the original hash" do - require "yaml" - expect(YAML.load(serializer.dump(hash))).to eq(hash) - end - end - end -end From 982d42e788b3ce95dbf6efb839f05e6d2a1251c3 Mon Sep 17 00:00:00 2001 From: SHIBATA Hiroshi Date: Thu, 17 May 2018 16:59:10 +0900 Subject: [PATCH 2/3] Fixed quoted string with YAML --- spec/commands/config_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index c0ef3bb70c5..596cd5b6fb8 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -325,7 +325,7 @@ it "doesn't return quotes around values" do bundle "config set foo '1'" run "puts Bundler.settings.send(:global_config_file).read" - expect(out).to include('"1"') + expect(out).to include("'1'") run "puts Bundler.settings[:foo]" expect(out).to eq("1") end From 4f01b28d95cef783dcd589d0c90f09b2aef6c600 Mon Sep 17 00:00:00 2001 From: SHIBATA Hiroshi Date: Thu, 14 Mar 2019 21:25:24 +0900 Subject: [PATCH 3/3] Removed psyched_yaml because the modern version of Ruby don't need it. --- lib/bundler.rb | 7 +++---- lib/bundler/plugin/index.rb | 4 ++-- lib/bundler/rubygems_integration.rb | 4 ++-- lib/bundler/settings.rb | 4 ++-- spec/bundler/bundler_spec.rb | 2 +- spec/bundler/psyched_yaml_spec.rb | 9 --------- spec/spec_helper.rb | 2 +- spec/support/hax.rb | 2 +- 8 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 spec/bundler/psyched_yaml_spec.rb diff --git a/lib/bundler.rb b/lib/bundler.rb index 1887457c779..f5e85c9f029 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -562,12 +562,11 @@ def reset_rubygems! private def eval_yaml_gemspec(path, contents) - require_relative "bundler/psyched_yaml" + Kernel.send(:require, "yaml") - # If the YAML is invalid, Syck raises an ArgumentError, and Psych - # raises a Psych::SyntaxError. See psyched_yaml.rb for more info. + # If the YAML is invalid, Psych raises a Psych::SyntaxError. Gem::Specification.from_yaml(contents) - rescue YamlLibrarySyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception + rescue Psych::SyntaxError, Gem::EndOfYAMLException, Gem::Exception eval_gemspec(path, contents) end diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 46189e871a9..3a0e58fa23f 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -139,7 +139,7 @@ def load_index(index_file, global = false) data = index_f.read - require_relative "psyched_yaml" + require "yaml" index = YAML.load(data) @commands.merge!(index["commands"]) @@ -162,7 +162,7 @@ def save_index "sources" => @sources, } - require_relative "psyched_yaml" + require "yaml" SharedHelpers.filesystem_access(index_file) do |index_f| FileUtils.mkdir_p(index_f.dirname) File.open(index_f, "w") {|f| f.puts YAML.dump(index) } diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 7549c592f1f..a64b1931489 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -119,7 +119,7 @@ def platforms end def configuration - require_relative "psyched_yaml" + require "yaml" Gem.configuration rescue Gem::SystemExitException, LoadError => e Bundler.ui.error "#{e.class}: #{e.message}" @@ -267,7 +267,7 @@ def with_build_args(args) def spec_from_gem(path, policy = nil) require "rubygems/security" - require_relative "psyched_yaml" + require "yaml" gem_from_path(path, security_policies[policy]).spec rescue Gem::Package::FormatError raise GemspecError, "Could not read gem at #{path}. It may be corrupted." diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 203e5e8f7b1..6c30925d210 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -352,7 +352,7 @@ def set_key(raw_key, value, hash, file) return unless file SharedHelpers.filesystem_access(file) do |p| FileUtils.mkdir_p(p.dirname) - require_relative "psyched_yaml" + require "yaml" p.open("w") {|f| f.write(YAML.dump(hash)) } end end @@ -392,7 +392,7 @@ def load_config(config_file) SharedHelpers.filesystem_access(config_file, :read) do |file| valid_file = file.exist? && !file.size.zero? return {} unless valid_file - require_relative "psyched_yaml" + require "yaml" YAML.load file.read end end diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 8a4ce729edd..16f8e0fafe1 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -37,7 +37,7 @@ context "with Psych as YAML::Engine" do it "raises a GemspecError after YAML load throws Psych::SyntaxError" do orig_yamler = YAML::ENGINE.yamler - YAML::ENGINE.yamler = "psych" + YAML::ENGINE.yamler = "yaml" expect { subject }.to raise_error(Bundler::GemspecError) diff --git a/spec/bundler/psyched_yaml_spec.rb b/spec/bundler/psyched_yaml_spec.rb deleted file mode 100644 index d5d68c5cc3c..00000000000 --- a/spec/bundler/psyched_yaml_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "bundler/psyched_yaml" - -RSpec.describe "Bundler::YamlLibrarySyntaxError" do - it "is raised on YAML parse errors" do - expect { YAML.parse "{foo" }.to raise_error(Bundler::YamlLibrarySyntaxError) - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f12b275479..d58e42f7917 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ $:.unshift File.expand_path("..", __FILE__) $:.unshift File.expand_path("../../lib", __FILE__) -require "bundler/psyched_yaml" +require "yaml" require "bundler/vendored_fileutils" require "uri" require "digest" diff --git a/spec/support/hax.rb b/spec/support/hax.rb index 74daccc9dba..cc19b72fab0 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -44,7 +44,7 @@ class Object begin # this has to be done up front because psych will try to load a .jar # if it thinks its on jruby - require "psych" + require "yaml" rescue LoadError nil end