Project

General

Profile

Actions

Bug #21709

open

Inconsistent encoding by Regexp.escape

Bug #21709: Inconsistent encoding by Regexp.escape

Added by thyresias (Thierry Lambert) about 19 hours ago. Updated about 12 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x64-mingw-ucrt]
[ruby-core:123894]

Description

%w(foo être).each do |s|
  puts "string: #{s.inspect} -> #{s.encoding}"
  puts "escaped: #{Regexp.escape(s).inspect} -> #{Regexp.escape(s).encoding}"
end

Output:

string: "foo" -> UTF-8
escaped: "foo" -> US-ASCII
string: "être" -> UTF-8
escaped: "être" -> UTF-8

The result should always match the encoding of the argument.

Actions

Also available in: PDF Atom