1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Merge psych-3.0.0.beta3 from ruby/psych.

* Rely on encoding tags to determine if string should be dumped as binary.
    8949a47b8c
  * 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
This commit is contained in:
hsbt 2017-07-14 06:15:58 +00:00
parent e870af8834
commit 0b396d5880
84 changed files with 144 additions and 108 deletions

View file

@ -1,5 +1,5 @@
# -*- coding: us-ascii -*- # -*- coding: us-ascii -*-
# frozen_string_literal: false # frozen_string_literal: true
require 'mkmf' require 'mkmf'
require 'fileutils' require 'fileutils'

View file

@ -1,11 +1,15 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/versions' require 'psych/versions'
case RUBY_ENGINE case RUBY_ENGINE
when 'jruby' when 'jruby'
require 'psych_jars' require 'psych_jars'
org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false) org.jruby.ext.psych.PsychLibrary.new.load(JRuby.runtime, false)
else else
begin
require "#{RUBY_VERSION[/\d+\.\d+/]}/psych.so"
rescue LoadError
require 'psych.so' require 'psych.so'
end
end end
require 'psych/nodes' require 'psych/nodes'
require 'psych/streaming' require 'psych/streaming'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/omap' require 'psych/omap'
require 'psych/set' require 'psych/set'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
### ###
# If an object defines +encode_with+, then an instance of Psych::Coder will # If an object defines +encode_with+, then an instance of Psych::Coder will

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
class Object class Object
def self.yaml_tag url def self.yaml_tag url
Psych.add_tag(url, self) Psych.add_tag(url, self)

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
class Exception < RuntimeError class Exception < RuntimeError
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
### ###
# Psych::Handler is an abstract base class that defines the events used # Psych::Handler is an abstract base class that defines the events used

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/tree_builder' require 'psych/tree_builder'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/handler' require 'psych/handler'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module JSON module JSON
module RubyEvents # :nodoc: module RubyEvents # :nodoc:

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/json/ruby_events' require 'psych/json/ruby_events'
require 'psych/json/yaml_events' require 'psych/json/yaml_events'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/json/yaml_events' require 'psych/json/yaml_events'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module JSON module JSON
module YAMLEvents # :nodoc: module YAMLEvents # :nodoc:

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/nodes/node' require 'psych/nodes/node'
require 'psych/nodes/stream' require 'psych/nodes/stream'
require 'psych/nodes/document' require 'psych/nodes/document'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'stringio' require 'stringio'
require 'psych/class_loader' require 'psych/class_loader'
require 'psych/scalar_scanner' require 'psych/scalar_scanner'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Nodes module Nodes
### ###

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
class Omap < ::Hash class Omap < ::Hash
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
### ###
# YAML event parser class. This class parses a YAML document and calls # YAML event parser class. This class parses a YAML document and calls

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'strscan' require 'strscan'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
class Set < ::Hash class Set < ::Hash
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
### ###
# Psych::Stream is a streaming YAML emitter. It will not buffer your YAML, # Psych::Stream is a streaming YAML emitter. It will not buffer your YAML,

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Streaming module Streaming
module ClassMethods module ClassMethods

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/exception' require 'psych/exception'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/handler' require 'psych/handler'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
# The version is Psych you're using # The version is Psych you're using
VERSION = '3.0.0.beta2' VERSION = '3.0.0.beta2'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/visitors/visitor' require 'psych/visitors/visitor'
require 'psych/visitors/to_ruby' require 'psych/visitors/to_ruby'
require 'psych/visitors/emitter' require 'psych/visitors/emitter'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Visitors module Visitors
class DepthFirst < Psych::Visitors::Visitor class DepthFirst < Psych::Visitors::Visitor

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Visitors module Visitors
class Emitter < Psych::Visitors::Visitor class Emitter < Psych::Visitors::Visitor

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/json/ruby_events' require 'psych/json/ruby_events'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/scalar_scanner' require 'psych/scalar_scanner'
require 'psych/class_loader' require 'psych/class_loader'
require 'psych/exception' require 'psych/exception'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Psych module Psych
module Visitors module Visitors
class Visitor class Visitor

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/tree_builder' require 'psych/tree_builder'
require 'psych/scalar_scanner' require 'psych/scalar_scanner'
require 'psych/class_loader' require 'psych/class_loader'
@ -321,7 +321,7 @@ module Psych
end end
@emitter.scalar o, nil, tag, plain, quote, style @emitter.scalar o, nil, tag, plain, quote, style
else else
maptag = '!ruby/string' maptag = '!ruby/string'.dup
maptag << ":#{o.class}" unless o.class == ::String maptag << ":#{o.class}" unless o.class == ::String
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK) register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
@ -378,14 +378,18 @@ module Psych
def visit_Array o def visit_Array o
if o.class == ::Array if o.class == ::Array
register o, @emitter.start_sequence(nil, nil, true, Nodes::Sequence::BLOCK) visit_Enumerator o
o.each { |c| accept c }
@emitter.end_sequence
else else
visit_array_subclass o visit_array_subclass o
end end
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 def visit_NilClass o
@emitter.scalar('', nil, 'tag:yaml.org,2002:null', true, false, Nodes::Scalar::ANY) @emitter.scalar('', nil, 'tag:yaml.org,2002:null', true, false, Nodes::Scalar::ANY)
end end
@ -411,15 +415,9 @@ module Psych
end end
private 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 def binary? string
(string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) || string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?
string.index(NULL) ||
string.count(BINARY_RANGE, WS_RANGE).fdiv(string.length) > 0.3
end end
def visit_array_subclass o def visit_array_subclass o

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
module Kernel module Kernel
### ###
# An alias for Psych.dump_stream meant to be used with IRB. # An alias for Psych.dump_stream meant to be used with IRB.

View file

@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# frozen_string_literal: true
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "psych" s.name = "psych"
@ -17,7 +18,25 @@ DESCRIPTION
s.require_paths = ["lib"] s.require_paths = ["lib"]
# for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } # for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
s.files = [".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console", "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", "lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb", "lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb", "lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb", "lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb", "lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb", "lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb", "lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"] s.files = [
".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console",
"bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h",
"ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h",
"ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h",
"ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c",
"ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c",
"ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h",
"lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/exception.rb",
"lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb",
"lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb",
"lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb",
"lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb",
"lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb",
"lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb",
"lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb",
"lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb",
"lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"
]
s.rdoc_options = ["--main", "README.md"] s.rdoc_options = ["--main", "README.md"]
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"] s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"]
@ -31,11 +50,15 @@ DESCRIPTION
if RUBY_ENGINE == 'jruby' if RUBY_ENGINE == 'jruby'
s.platform = 'java' s.platform = 'java'
s.files.concat ["ext/java/PsychEmitter.java", "ext/java/PsychLibrary.java", "ext/java/PsychParser.java", "ext/java/PsychToRuby.java", "ext/java/PsychYamlTree.java", "lib/psych_jars.rb", "lib/psych.jar"] s.files.concat [
"ext/java/PsychEmitter.java", "ext/java/PsychLibrary.java", "ext/java/PsychParser.java", "ext/java/PsychToRuby.java",
"ext/java/PsychYamlTree.java", "lib/psych_jars.rb", "lib/psych.jar"
]
s.requirements = "jar org.yaml:snakeyaml, 1.18" s.requirements = "jar org.yaml:snakeyaml, 1.18"
s.add_dependency 'jar-dependencies', '>= 0.1.7' s.add_dependency 'jar-dependencies', '>= 0.1.7'
s.add_development_dependency 'ruby-maven' s.add_development_dependency 'ruby-maven'
else else
s.extensions = ["ext/psych/extconf.rb"] s.extensions = ["ext/psych/extconf.rb"]
s.add_development_dependency 'rake-compiler-dock', ">= 0.6.1"
end end
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
require 'psych/handlers/recorder' require 'psych/handlers/recorder'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'minitest/autorun' require 'minitest/autorun'
require 'stringio' require 'stringio'
require 'tempfile' require 'tempfile'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
class ObjectWithInstanceVariables class ObjectWithInstanceVariables

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych
@ -15,6 +15,12 @@ module Psych
@list = [{ :a => 'b' }, 'foo'] @list = [{ :a => 'b' }, 'foo']
end end
def test_enumerator
x = [1, 2, 3, 4]
y = Psych.load Psych.dump x.to_enum
assert_equal x, y
end
def test_another_subclass_with_attributes def test_another_subclass_with_attributes
y = Y.new.tap {|o| o.val = 1} y = Y.new.tap {|o| o.val = 1}
y << "foo" << "bar" y << "foo" << "bar"

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'date' require 'date'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
@ -7,7 +7,7 @@ module Psych
class TestEmitter < TestCase class TestEmitter < TestCase
def setup def setup
super super
@out = StringIO.new('') @out = StringIO.new(''.dup)
@emitter = Psych::Emitter.new @out @emitter = Psych::Emitter.new @out
end end

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'delegate' require 'delegate'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'bigdecimal' require 'bigdecimal'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# coding: utf-8 # coding: utf-8
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'stringio' require 'stringio'
@ -84,7 +84,7 @@ class TestPsych < Psych::TestCase
def test_dump_io def test_dump_io
hash = {'hello' => 'TGIF!'} hash = {'hello' => 'TGIF!'}
stringio = StringIO.new '' stringio = StringIO.new ''.dup
assert_equal stringio, Psych.dump(hash, stringio) assert_equal stringio, Psych.dump(hash, stringio)
assert_equal Psych.dump(hash), stringio.string assert_equal Psych.dump(hash), stringio.string
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
@ -8,5 +8,10 @@ module Psych
def test_utf_8 def test_utf_8
assert_equal "日本語", Psych.load("--- 日本語") assert_equal "日本語", Psych.load("--- 日本語")
end end
def test_some_bytes # Ticket #278
x = "\xEF\xBF\xBD\x1F"
assert_cycle x
end
end end
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'date' require 'date'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# encoding: UTF-8 # encoding: UTF-8
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych
@ -166,7 +166,7 @@ string: &70121654388580 !ruby/string
end end
def test_nonascii_string_as_binary def test_nonascii_string_as_binary
string = "hello \x80 world!" string = "hello \x80 world!".dup
string.force_encoding 'ascii-8bit' string.force_encoding 'ascii-8bit'
yml = Psych.dump string yml = Psych.dump string
assert_match(/binary/, yml) assert_match(/binary/, yml)
@ -174,7 +174,7 @@ string: &70121654388580 !ruby/string
end end
def test_binary_string_null def test_binary_string_null
string = "\x00" string = "\x00\x92".b
yml = Psych.dump string yml = Psych.dump string
assert_match(/binary/, yml) assert_match(/binary/, yml)
assert_equal string, Psych.load(yml) assert_equal string, Psych.load(yml)
@ -187,8 +187,8 @@ string: &70121654388580 !ruby/string
assert_equal string, Psych.load(yml) assert_equal string, Psych.load(yml)
end end
def test_non_binary_string def test_ascii_only_binary_string
string = binary_string(0.29) string = "non bnry string".b
yml = Psych.dump string yml = Psych.dump string
refute_match(/binary/, yml) refute_match(/binary/, yml)
assert_equal string, Psych.load(yml) assert_equal string, Psych.load(yml)
@ -202,7 +202,7 @@ string: &70121654388580 !ruby/string
end end
def test_string_with_ivars def test_string_with_ivars
food = "is delicious" food = "is delicious".dup
ivar = "on rock and roll" ivar = "on rock and roll"
food.instance_variable_set(:@we_built_this_city, ivar) food.instance_variable_set(:@we_built_this_city, ivar)
@ -220,9 +220,9 @@ string: &70121654388580 !ruby/string
end end
def binary_string percentage = 0.31, length = 100 def binary_string percentage = 0.31, length = 100
string = '' string = ''.b
(percentage * length).to_i.times do |i| (percentage * length).to_i.times do |i|
string << "\b" string << "\x92".b
end end
string << 'a' * (length - string.length) string << 'a' * (length - string.length)
string string

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
class PsychStructWithIvar < Struct.new(:foo) class PsychStructWithIvar < Struct.new(:foo)

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych
@ -90,7 +90,7 @@ module Psych
end end
def assert_taintedness string def assert_taintedness string
@parser.parse string.taint @parser.parse string.dup.taint
end end
end end

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# -*- coding: us-ascii; mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- # -*- coding: us-ascii; mode: ruby; ruby-indent-level: 4; tab-width: 4 -*-
# frozen_string_literal: false # frozen_string_literal: true
# vim:sw=4:ts=4 # vim:sw=4:ts=4
# $Id$ # $Id$
# #

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'tmpdir' require 'tmpdir'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require_relative 'helper' require_relative 'helper'
require 'yaml/store' require 'yaml/store'
require 'tmpdir' require 'tmpdir'

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,5 +1,5 @@
# coding: US-ASCII # coding: US-ASCII
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych

View file

@ -1,4 +1,4 @@
# frozen_string_literal: false # frozen_string_literal: true
require 'psych/helper' require 'psych/helper'
module Psych module Psych
@ -37,7 +37,7 @@ module Psych
end end
def test_binary_formatting def test_binary_formatting
gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;" gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;".b
@v << gif @v << gif
scalar = @v.tree.children.first.children.first scalar = @v.tree.children.first.children.first
assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style