Project

General

Profile

Bug #15718 ยป yamldumputf32encodingerror.patch

rubenochiavone (Ruben Chiavone), 03/21/2019 02:11 PM

View differences:

ext/psych/lib/psych/visitors/yaml_tree.rb (working copy)
style = Nodes::Scalar::PLAIN
tag = nil
# regexps
literal_regexp = /\n(?!\Z)/
double_quoted_regexp = /^[^[:word:]][^"]*$/
single_quoted_regexp = /\A0[0-7]*[89]/
if binary?(o)
o = [o].pack('m0')
tag = '!binary' # FIXME: change to below when syck is removed
......
style = Nodes::Scalar::LITERAL
plain = false
quote = false
elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
# match \n except blank line at the end of string
elsif string_match? o, literal_regexp
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
......
quote = false
elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/
elsif string_match? o, double_quoted_regexp
style = Nodes::Scalar::DOUBLE_QUOTED
elsif not String === @ss.tokenize(o) or /\A0[0-7]*[89]/ =~ o
elsif not String === @ss.tokenize(o) or string_match? o, single_quoted_regexp
style = Nodes::Scalar::SINGLE_QUOTED
end
......
string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?
end
def string_match? string, regexp
(string.encoding.ascii_compatible? || string.encoding == regexp.encoding) && string =~ regexp
end
def visit_array_subclass o
tag = "!ruby/array:#{o.class}"
ivars = o.instance_variables
test/yaml/test_dump.rb (working copy)
# frozen_string_literal: true
require 'test/unit'
require 'yaml'
require 'tmpdir'
class YAMLDumpTest < Test::Unit::TestCase
def test_dump_with_empty_utf32le_string
bug15718 = '[ruby-dev:91903]'
assert_nothing_raised bug15718 do
YAML.dump(''.dup.force_encoding('UTF-32LE'))
end
end
end
    (1-1/1)