diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 01:52:26 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-01 01:52:26 +0000 |
commit | 44320c5b8d780a1572206735a88212faf9428f11 (patch) | |
tree | 33badfda3fb40eae5ce52c0e4882ae887f3df3cd | |
parent | b4070513dde45474486955fbe1a3f3e5d787a342 (diff) | |
download | ruby-44320c5b8d780a1572206735a88212faf9428f11.tar.gz |
Merge psych-3.0.0.
See NEWS file for this update details.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60951 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | NEWS | 12 | ||||
-rw-r--r-- | ext/psych/lib/psych.rb | 13 | ||||
-rw-r--r-- | ext/psych/lib/psych/versions.rb | 2 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 2 | ||||
-rw-r--r-- | ext/psych/psych.gemspec | 4 | ||||
-rw-r--r-- | test/psych/test_psych.rb | 14 | ||||
-rw-r--r-- | test/psych/test_string.rb | 7 |
7 files changed, 33 insertions, 21 deletions
@@ -187,7 +187,17 @@ with all sufficient information, see the ChangeLog file or Redmine * 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: diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index dfb6c1b00e..0f14fe445c 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -252,6 +252,13 @@ module Psych # 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 # # 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 else visitor = Visitors::NoAliasRuby.new scanner, class_loader end - visitor.accept result + result = visitor.accept result + symbolize_names!(result) if symbolize_names + result end ### diff --git a/ext/psych/lib/psych/versions.rb b/ext/psych/lib/psych/versions.rb index cf5fc4116e..79dbe2523c 100644 --- a/ext/psych/lib/psych/versions.rb +++ b/ext/psych/lib/psych/versions.rb @@ -1,7 +1,7 @@ # 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 diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index f44e973c52..cfed8f1814 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -304,7 +304,7 @@ module Psych 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 diff --git a/ext/psych/psych.gemspec b/ext/psych/psych.gemspec index bbebce8776..23e02da89b 100644 --- a/ext/psych/psych.gemspec +++ b/ext/psych/psych.gemspec @@ -3,10 +3,10 @@ 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@tenderlovemaking.com", "hsbt@ruby-lang.org", "headius@headius.com"] - 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] diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index ff5ffbafc6..82906f0af6 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -184,20 +184,20 @@ class TestPsych < Psych::TestCase 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 diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index e80d19194b..973f38b9c2 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -37,13 +37,6 @@ module Psych 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 |