diff options
Diffstat (limited to 'spec/ruby/library/yaml/load_spec.rb')
-rw-r--r-- | spec/ruby/library/yaml/load_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/library/yaml/load_spec.rb b/spec/ruby/library/yaml/load_spec.rb index 7c5a33d52f..6a2ab65b65 100644 --- a/spec/ruby/library/yaml/load_spec.rb +++ b/spec/ruby/library/yaml/load_spec.rb @@ -34,6 +34,27 @@ describe "YAML.load" do end end + it "loads strings with chars from non-base Unicode plane" do + # We add these strings as bytes and force the encoding for safety + # as bugs in parsing unicode characters can obscure bugs in this + # area. + + yaml_and_strings = { + # "--- 🌵" => "🌵" + [45, 45, 45, 32, 240, 159, 140, 181] => + [240, 159, 140, 181], + # "--- 🌵 and some text" => "🌵 and some text" + [45, 45, 45, 32, 240, 159, 140, 181, 32, 97, 110, 100, 32, 115, 111, 109, 101, 32, 116, 101, 120, 116] => + [240, 159, 140, 181, 32, 97, 110, 100, 32, 115, 111, 109, 101, 32, 116, 101, 120, 116], + # "--- Some text 🌵 and some text" => "Some text 🌵 and some text" + [45, 45, 45, 32, 83, 111, 109, 101, 32, 116, 101, 120, 116, 32, 240, 159, 140, 181, 32, 97, 110, 100, 32, 115, 111, 109, 101, 32, 116, 101, 120, 116] => + [83, 111, 109, 101, 32, 116, 101, 120, 116, 32, 240, 159, 140, 181, 32, 97, 110, 100, 32, 115, 111, 109, 101, 32, 116, 101, 120, 116] + } + yaml_and_strings.each do |yaml, str| + YAML.load(yaml.pack("C*").force_encoding("UTF-8")).should == str.pack("C*").force_encoding("UTF-8") + end + end + it "fails on invalid keys" do if YAML.to_s == "Psych" error = Psych::SyntaxError |