diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-17 20:52:46 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-17 20:52:46 +0000 |
commit | 2845bfa9dd648a2ea3c8e753bdeeddbcdf4f203a (patch) | |
tree | 230229a4998f359627d9c0ed5e3ffa05cffd44b1 | |
parent | 1cae325a3504f551ad968e8562756b05ed29b682 (diff) | |
download | ruby-2845bfa9dd648a2ea3c8e753bdeeddbcdf4f203a.tar.gz |
* ext/psych/lib/psych/visitors/yaml_tree.rb: defaulting binary string
format to "literal" format.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 7 | ||||
-rw-r--r-- | test/psych/visitors/test_yaml_tree.rb | 7 |
3 files changed, 17 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Sun Apr 18 05:50:58 2010 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: defaulting binary string + format to "literal" format. + Sun Apr 18 02:13:59 2010 NARUSE, Yui <naruse@ruby-lang.org> * lib/irb/ruby-lex.rb (identify_identifier): add '_' to the regexp. diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index c70f24886e..5e773c921e 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -171,10 +171,13 @@ module Psych def visit_String o plain = false quote = false + style = Nodes::Scalar::ANY if o.index("\x00") || o.count("^ -~\t\r\n").fdiv(o.length) > 0.3 str = [o].pack('m').chomp - tag = '!binary' + tag = '!binary' # FIXME: change to below when syck is removed + #tag = 'tag:yaml.org,2002:binary' + style = Nodes::Scalar::LITERAL else str = o tag = nil @@ -184,7 +187,7 @@ module Psych ivars = find_ivars o - scalar = create_scalar str, nil, tag, plain, quote + scalar = create_scalar str, nil, tag, plain, quote, style if ivars.empty? append scalar diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index 7f6f502b1c..292710b00d 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -8,6 +8,13 @@ module Psych @v = Visitors::YAMLTree.new end + 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;" + @v << gif + scalar = @v.tree.children.first.children.first + assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style + end + def test_object_has_no_class yaml = Psych.dump(Object.new) assert(Psych.dump(Object.new) !~ /Object/, yaml) |