Issue #21709 has been updated by thyresias (Thierry Lambert). Subject changed from Inconsistent encoding by Regexp.escape to Regexp interpolation is inconsistent with String interpolation jeremyevans0 (Jeremy Evans) wrote in #note-7:
Sure, that sounds like a good idea.
It seems I cannot change the description, just the title. Should I open a new bug report? As an aside, you said about the encoding of the result of `Regexp.escape`:
This is not a bug, it is deliberate behavior for ASCII-only strings in `rb_reg_quote` (internal function called by `Regexp.escape`):
What is the logic in this? It's surprising that the encoding of the output does not match the encoding of the input, and I read somewhere that Matz follows the principle of least surprise... ---------------------------------------- Bug #21709: Regexp interpolation is inconsistent with String interpolation https://bugs.ruby-lang.org/issues/21709#change-115330 * Author: thyresias (Thierry Lambert) * Status: Open * ruby -v: ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x64-mingw-ucrt] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ```ruby %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. -- https://bugs.ruby-lang.org/