Project

General

Profile

Actions

Bug #19455

closed

Ruby 3.2: wrong Regexp encoding with non-ASCII comments

Added by janosch-x (Janosch Müller) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0 (2022-12-25 revision a528908271)
[ruby-core:112533]

Description

comments and comment groups don't trigger the correct Regexp#encoding on Ruby 3.2 anymore:

# ruby 3.1
/#a/x.encoding          # => #<Encoding:US-ASCII> # OK
/(?#a)/.encoding        # => #<Encoding:US-ASCII> # OK
/#ü/x.encoding          # => #<Encoding:UTF-8>    # OK
/(?#ü)/.encoding        # => #<Encoding:UTF-8>    # OK

# ruby 3.2
/#a/x.encoding          # => #<Encoding:US-ASCII> # OK
/(?#a)/.encoding        # => #<Encoding:US-ASCII> # OK
/#ü/x.encoding          # => #<Encoding:US-ASCII> # BUG
/(?#ü)/.encoding        # => #<Encoding:US-ASCII> # BUG

/#ü/x.inspect           # => "/#\\xC3\\xBC/x"
/(?#ü)/.inspect         # => "/(?#\\xC3\\xBC)/"

# bug is hidden if there are non-ascii chars outside comments
/ü#ü/x.encoding         # => #<Encoding:UTF-8>
/ü(?#ü)/.encoding       # => #<Encoding:UTF-8>

i think these changes might be the cause: https://github.com/ruby/ruby/commit/ec3542229b29ec93062e9d90e877ea29d3c19472#diff-c3675fa319803b2f5a775defa40694edb9a761baa3a54fa78e1fdef8f918cc7cR2837-R2890

@jeremyevans0 (Jeremy Evans) JFYI

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0