diff options
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 2 | ||||
-rw-r--r-- | test/psych/test_string.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index 2afedb7..f40538a 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -291,7 +291,7 @@ module Psych quote = false elsif o =~ /\n/ style = Nodes::Scalar::LITERAL - 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 f1f061b..68917c8 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 @@ -19,6 +20,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) |