From: rubenochiavone@... Date: 2019-03-21T14:12:14+00:00 Subject: [ruby-core:91914] [Ruby trunk Bug#15718] YAML raises error when dumping strings with UTF32 encoding Issue #15718 has been updated by rubenochiavone (Ruben Chiavone). File yamldumputf32encodingerror.patch added marcandre (Marc-Andre Lafortune) wrote: > ```shell > ruby -r yaml -e "p YAML.dump( ''.force_encoding('UTF-32LE') )" > > Traceback (most recent call last): > 4: from -e:1:in `
' > 3: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych.rb:513:in `dump' > 2: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:118:in `push' > 1: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:136:in `accept' > /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:298:in `visit_String': incompatible encoding regexp match (US-ASCII regexp with UTF-32LE string) (Encoding::CompatibilityError) > ``` > > Surprisingly, this works in Ruby 2.4.x, but not in 2.2, 2.3, 2.5 nor 2.6! nobu (Nobuyoshi Nakada) wrote: > It may be related to a code range bug. > By adding `o.valid_encoding?` to `Psych::Visitors::YAMLTree#visit_String`, the error raises in ruby 24 too. Since it relates to mismatch of regex and YAML text encoding a possible fix is to only attempt to match the text when encoding matches or when text encoding is `ascii_compatible?`. WTDY? Still I'm not sure why on other versions it works. Anyhow, I'm adding a patch that reproduces and fixes this issues (hopefully). ---------------------------------------- Bug #15718: YAML raises error when dumping strings with UTF32 encoding https://bugs.ruby-lang.org/issues/15718#change-77244 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.6.2p247 * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- ```shell ruby -r yaml -e "p YAML.dump( ''.force_encoding('UTF-32LE') )" Traceback (most recent call last): 4: from -e:1:in `
' 3: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych.rb:513:in `dump' 2: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:118:in `push' 1: from /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:136:in `accept' /Users/work/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/psych/visitors/yaml_tree.rb:298:in `visit_String': incompatible encoding regexp match (US-ASCII regexp with UTF-32LE string) (Encoding::CompatibilityError) ``` Surprisingly, this works in Ruby 2.4.x, but not in 2.2, 2.3, 2.5 nor 2.6! ---Files-------------------------------- yamldumputf32encodingerror.patch (2.55 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: