diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2014-08-16 16:49:52 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2014-08-16 17:42:57 +0200 |
commit | 010d0c37bde30c5f347ebfd69087a487ff8b8bbb (patch) | |
tree | 9331389c409fa806de6299273e569e97455abfe5 | |
parent | 0c4ee55072bf5b5bb64c66157f71ba6442f597db (diff) | |
download | psych-010d0c37bde30c5f347ebfd69087a487ff8b8bbb.tar.gz |
Don't quote scalar values beginning with non-ASCII character
-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) |