ruby-changes:48834
From: hsbt <ko1@a...>
Date: Fri, 1 Dec 2017 10:52:31 +0900 (JST)
Subject: [ruby-changes:48834] hsbt:r60951 (trunk): Merge psych-3.0.0.
hsbt 2017-12-01 10:52:26 +0900 (Fri, 01 Dec 2017) New Revision: 60951 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60951 Log: Merge psych-3.0.0. See NEWS file for this update details. Modified files: trunk/NEWS trunk/ext/psych/lib/psych/versions.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/ext/psych/lib/psych.rb trunk/ext/psych/psych.gemspec trunk/test/psych/test_psych.rb trunk/test/psych/test_string.rb Index: NEWS =================================================================== --- NEWS (revision 60950) +++ NEWS (revision 60951) @@ -187,7 +187,17 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L187 * Psych - * Update to Psych 3.0.0.beta3. + * Update to Psych 3.0.0. + * Add :symbolize_names option to Psych.load, Psych.safe_load like JSON.parse + https://github.com/ruby/psych/pull/333, https://github.com/ruby/psych/pull/337 + * Add Psych::Handler#event_location + https://github.com/ruby/psych/pull/326 + * Make frozen string literal = true + https://github.com/ruby/psych/pull/320 + * Preserve time zone offset when deserializing times + https://github.com/ruby/psych/pull/316 + * Removed deprecated method aliases for syck gem + https://github.com/ruby/psych/pull/312 * RbConfig * New constants: Index: ext/psych/lib/psych/versions.rb =================================================================== --- ext/psych/lib/psych/versions.rb (revision 60950) +++ ext/psych/lib/psych/versions.rb (revision 60951) @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/versions.rb#L1 # frozen_string_literal: true module Psych # The version is Psych you're using - VERSION = '3.0.0.beta4' + VERSION = '3.0.0' if RUBY_ENGINE == 'jruby' DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 60950) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 60951) @@ -304,7 +304,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L304 quote = false elsif @line_width && o.length > @line_width style = Nodes::Scalar::FOLDED - elsif o =~ /^[^[:word:]][^"]*$/ or o =~ /^([^"]*'+[^"]*)+$/ + elsif o =~ /^[^[:word:]][^"]*$/ style = Nodes::Scalar::DOUBLE_QUOTED elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o style = Nodes::Scalar::SINGLE_QUOTED Index: ext/psych/lib/psych.rb =================================================================== --- ext/psych/lib/psych.rb (revision 60950) +++ ext/psych/lib/psych.rb (revision 60951) @@ -252,6 +252,13 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L252 # ex.file # => 'file.txt' # ex.message # => "(file.txt): found character that cannot start any token" # end + # + # When the optional +symbolize_names+ keyword argument is set to a + # true value, returns symbols for keys in Hash objects (default: strings). + # + # Psych.load("---\n foo: bar") # => {"foo"=>"bar"} + # Psych.load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"} + # def self.load yaml, filename = nil, fallback = false, symbolize_names: false result = parse(yaml, filename, fallback) result = result.to_ruby if result @@ -293,7 +300,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L300 # # A Psych::BadAlias exception will be raised if the yaml contains aliases # but the +aliases+ parameter is set to false. - def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil + def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil, symbolize_names: false result = parse(yaml, filename) return unless result @@ -305,7 +312,9 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych.rb#L312 else visitor = Visitors::NoAliasRuby.new scanner, class_loader end - visitor.accept result + result = visitor.accept result + symbolize_names!(result) if symbolize_names + result end ### Index: ext/psych/psych.gemspec =================================================================== --- ext/psych/psych.gemspec (revision 60950) +++ ext/psych/psych.gemspec (revision 60951) @@ -3,10 +3,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/psych/psych.gemspec#L3 Gem::Specification.new do |s| s.name = "psych" - s.version = "3.0.0.beta4" + s.version = "3.0.0" s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"] s.email = ["aaron@t...", "hsbt@r...", "headius@h..."] - s.date = "2017-11-27" + s.date = "2017-12-01" s.summary = "Psych is a YAML parser and emitter" s.description = <<-DESCRIPTION Psych is a YAML parser and emitter. Psych leverages libyaml[http://pyyaml.org/wiki/LibYAML] Index: test/psych/test_string.rb =================================================================== --- test/psych/test_string.rb (revision 60950) +++ test/psych/test_string.rb (revision 60951) @@ -37,13 +37,6 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_string.rb#L37 assert_equal str, Psych.load(yaml) end - def test_doublequotes_when_there_are_single_quotes_only - str = "psych: Please don't escape ' with ' here." - yaml = Psych.dump str - assert_equal "--- \"psych: Please don't escape ' with ' here.\"\n", yaml - assert_equal str, Psych.load(yaml) - end - def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12 Index: test/psych/test_psych.rb =================================================================== --- test/psych/test_psych.rb (revision 60950) +++ test/psych/test_psych.rb (revision 60951) @@ -184,20 +184,20 @@ class TestPsych < Psych::TestCase https://github.com/ruby/ruby/blob/trunk/test/psych/test_psych.rb#L184 end def test_symbolize_names - result = Psych.load(<<-eoyml) + yaml = <<-eoyml foo: bar: baz hoge: - fuga: piyo eoyml + + result = Psych.load(yaml) assert_equal result, { "foo" => { "bar" => "baz"}, "hoge" => [{ "fuga" => "piyo" }] } - result = Psych.load(<<-eoyml, symbolize_names: true) -foo: - bar: baz -hoge: - - fuga: piyo - eoyml + result = Psych.load(yaml, symbolize_names: true) + assert_equal result, { foo: { bar: "baz" }, hoge: [{ fuga: "piyo" }] } + + result = Psych.safe_load(yaml, symbolize_names: true) assert_equal result, { foo: { bar: "baz" }, hoge: [{ fuga: "piyo" }] } end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/