From 344b8bbd697ba7ade949da3968b9f5e6226f832f Mon Sep 17 00:00:00 2001 From: tenderlove Date: Thu, 8 Jan 2015 22:25:31 +0000 Subject: * ext/psych/lib/psych/visitors/yaml_tree.rb: correctly quote non-ascii letters. Thanks @jirutka for the patch. * test/psych/test_string.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/psych/lib/psych/visitors/yaml_tree.rb | 2 +- test/psych/test_string.rb | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8b81ae39dd..efda708504 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Jan 9 07:23:32 2015 Aaron Patterson + + * ext/psych/lib/psych/visitors/yaml_tree.rb: correctly quote non-ascii + letters. Thanks @jirutka for the patch. + + * test/psych/test_string.rb: test for change + Fri Jan 9 07:13:55 2015 Aaron Patterson * ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index bedf9d35b2..3a6bd1da54 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -317,7 +317,7 @@ module Psych tag = 'tag:yaml.org,2002:str' plain = false quote = false - elsif o =~ /^\W[^"]*$/ + elsif o =~ /^[^[:word:]][^"]*$/ style = Nodes::Scalar::DOUBLE_QUOTED else unless String === @ss.tokenize(o) diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 1ce16fdf3e..26a4e201e5 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require_relative 'helper' module Psych @@ -23,6 +24,11 @@ module Psych assert_equal 2, Psych.dump(%Q{<%= ENV["PATH"] %>}).count('"') end + def test_no_quotes_when_start_with_non_ascii_character + yaml = Psych.dump 'Český non-ASCII'.encode(Encoding::UTF_8) + assert_match(/---\s*[^"'!]+$/, yaml) + end + def test_doublequotes_when_there_is_a_single yaml = Psych.dump "@123'abc" assert_match(/---\s*"/, yaml) -- cgit v1.2.3