summaryrefslogtreecommitdiff
path: root/ext/psych/lib
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-24 09:06:08 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-24 09:06:08 +0000
commita099c5420c371d941953358896de861030fda421 (patch)
tree5e3555134a652cf8c927afcaaba299fd94d44531 /ext/psych/lib
parent656c458665324a674e703cc65927696ad3210820 (diff)
* ext/psych/*, test/psych/*: Upate psych 2.1.0
This version fixed [Bug #11988][ruby-core:72850] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib')
-rw-r--r--ext/psych/lib/psych.rb21
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb2
2 files changed, 14 insertions, 9 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb
index f442e544ce..15371cde58 100644
--- a/ext/psych/lib/psych.rb
+++ b/ext/psych/lib/psych.rb
@@ -224,11 +224,13 @@ require 'psych/class_loader'
module Psych
# The version is Psych you're using
- VERSION = '2.0.17'
+ VERSION = '2.1.0'
# The version of libyaml Psych is using
LIBYAML_VERSION = Psych.libyaml_version.join '.'
+ FALLBACK = Struct.new :to_ruby # :nodoc:
+
###
# Load +yaml+ in to a Ruby data structure. If multiple documents are
# provided, the object contained in the first document will be returned.
@@ -248,8 +250,8 @@ module Psych
# ex.file # => 'file.txt'
# ex.message # => "(file.txt): found character that cannot start any token"
# end
- def self.load yaml, filename = nil
- result = parse(yaml, filename)
+ def self.load yaml, filename = nil, fallback = false
+ result = parse(yaml, filename, fallback)
result ? result.to_ruby : result
end
@@ -321,11 +323,11 @@ module Psych
# end
#
# See Psych::Nodes for more information about YAML AST.
- def self.parse yaml, filename = nil
+ def self.parse yaml, filename = nil, fallback = false
parse_stream(yaml, filename) do |node|
return node
end
- false
+ fallback
end
###
@@ -466,9 +468,12 @@ module Psych
###
# Load the document contained in +filename+. Returns the yaml contained in
- # +filename+ as a Ruby object
- def self.load_file filename
- File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
+ # +filename+ as a Ruby object, or if the file is empty, it returns
+ # the specified default return value, which defaults to an empty Hash
+ def self.load_file filename, fallback = false
+ File.open(filename, 'r:bom|utf-8') { |f|
+ self.load f, filename, FALLBACK.new(fallback)
+ }
end
# :stopdoc:
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 7c400504fa..11214ecbf4 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -331,7 +331,7 @@ module Psych
style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/
style = Nodes::Scalar::DOUBLE_QUOTED
- elsif not String === @ss.tokenize(o)
+ elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
style = Nodes::Scalar::SINGLE_QUOTED
end