From 0b396d588060707e227f21b80e964180674c8a50 Mon Sep 17 00:00:00 2001 From: hsbt Date: Fri, 14 Jul 2017 06:15:58 +0000 Subject: Merge psych-3.0.0.beta3 from ruby/psych. * Rely on encoding tags to determine if string should be dumped as binary. https://github.com/ruby/psych/commit/8949a47b8cee31e03e21608406ba116adcf74054 * Specify "frozen_string_literal: true". * Support to binary release for mingw32 platform. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych/visitors/depth_first.rb | 2 +- ext/psych/lib/psych/visitors/emitter.rb | 2 +- ext/psych/lib/psych/visitors/json_tree.rb | 2 +- ext/psych/lib/psych/visitors/to_ruby.rb | 2 +- ext/psych/lib/psych/visitors/visitor.rb | 2 +- ext/psych/lib/psych/visitors/yaml_tree.rb | 22 ++++++++++------------ 6 files changed, 15 insertions(+), 17 deletions(-) (limited to 'ext/psych/lib/psych/visitors') diff --git a/ext/psych/lib/psych/visitors/depth_first.rb b/ext/psych/lib/psych/visitors/depth_first.rb index 2d74a212d6..b4ff9e40e7 100644 --- a/ext/psych/lib/psych/visitors/depth_first.rb +++ b/ext/psych/lib/psych/visitors/depth_first.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true module Psych module Visitors class DepthFirst < Psych::Visitors::Visitor diff --git a/ext/psych/lib/psych/visitors/emitter.rb b/ext/psych/lib/psych/visitors/emitter.rb index f2ff9fdb28..e3b92b7d03 100644 --- a/ext/psych/lib/psych/visitors/emitter.rb +++ b/ext/psych/lib/psych/visitors/emitter.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true module Psych module Visitors class Emitter < Psych::Visitors::Visitor diff --git a/ext/psych/lib/psych/visitors/json_tree.rb b/ext/psych/lib/psych/visitors/json_tree.rb index f2f0215cd2..9912cb1362 100644 --- a/ext/psych/lib/psych/visitors/json_tree.rb +++ b/ext/psych/lib/psych/visitors/json_tree.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/json/ruby_events' module Psych diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index d1318b3ca0..74a52df866 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/scalar_scanner' require 'psych/class_loader' require 'psych/exception' diff --git a/ext/psych/lib/psych/visitors/visitor.rb b/ext/psych/lib/psych/visitors/visitor.rb index d97bf550f6..3f4ba64e57 100644 --- a/ext/psych/lib/psych/visitors/visitor.rb +++ b/ext/psych/lib/psych/visitors/visitor.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true module Psych module Visitors class Visitor diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index e197a30611..cfed8f1814 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true require 'psych/tree_builder' require 'psych/scalar_scanner' require 'psych/class_loader' @@ -321,7 +321,7 @@ module Psych end @emitter.scalar o, nil, tag, plain, quote, style else - maptag = '!ruby/string' + maptag = '!ruby/string'.dup maptag << ":#{o.class}" unless o.class == ::String register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK) @@ -378,14 +378,18 @@ module Psych def visit_Array o if o.class == ::Array - register o, @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK) - o.each { |c| accept c } - @emitter.end_sequence + visit_Enumerator o else visit_array_subclass o end end + def visit_Enumerator o + register o, @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK) + o.each { |c| accept c } + @emitter.end_sequence + end + def visit_NilClass o @emitter.scalar('', nil, 'tag:yaml.org,2002:null', true, false, Nodes::Scalar::ANY) end @@ -411,15 +415,9 @@ module Psych end private - # FIXME: Remove the index and count checks in Psych 3.0 - NULL = "\x00" - BINARY_RANGE = "\x00-\x7F" - WS_RANGE = "^ -~\t\r\n" def binary? string - (string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) || - string.index(NULL) || - string.count(BINARY_RANGE, WS_RANGE).fdiv(string.length) > 0.3 + string.encoding == Encoding::ASCII_8BIT && !string.ascii_only? end def visit_array_subclass o -- cgit v1.2.3