From: "mame (Yusuke Endoh)" Date: 2021-12-29T05:06:35+00:00 Subject: [ruby-core:106894] [Ruby master Bug#18449] Bug in 3.1 regexp literals with \c Issue #18449 has been updated by mame (Yusuke Endoh). Looks like `\c?` in a regexp literal was changed for #14367. ``` p(/\cC/.source) #=> "\\cC" in Ruby 3.0 p(/\cC/.source) #=> "\\x03" in Ruby 3.1 ``` @jeremyevans0 What do you think? ---------------------------------------- Bug #18449: Bug in 3.1 regexp literals with \c https://bugs.ruby-lang.org/issues/18449#change-95703 * Author: zenspider (Ryan Davis) * Status: Open * Priority: Normal * Target version: 3.1 * ruby -v: 3.1.0 ---------------------------------------- This file passes on 2.7, 3.0, and fails (if you remove the `skip` line) on 3.1: ``` ruby #!/usr/bin/env ruby -w require "minitest/autorun" class TestRegexpCreation < Minitest::Test R31 = RUBY_VERSION > "3.1" def test_literal_equivalence if R31 then assert_equal(/\x03/, /\cC/) # wrong! (note the assert) else refute_equal(/\x03/, /\cC/) end end def test_from_literal re = /\cC/ assert_equal(/\cC/, re) if R31 then assert_equal "\\x03", re.source # wrong? else assert_equal "\\cC", re.source end end def test_from_source re = Regexp.new "\\cC" assert_equal "\\cC", re.source if R31 then # wrong! skip assert_equal(/\cC/, re) # can't be written to pass assert_equal(/\x03/, re) # can't be written to pass else assert_equal(/\cC/, re) end end end # on 3.1: # # if written as: # # assert_equal(/\x03/, re) # # it fails with: # # 1) Failure: # TestRegexpCreation#test_source [regexp31.rb:32]: # Expected: /\x03/ # Actual: /\cC/ # # but if written as: # # assert_equal(/\cC/, re) # # it ALSO fails with: # # 1) Failure: # TestRegexpCreation#test_source [regexp31.rb:32]: # Expected: /\x03/ # Actual: /\cC/ ``` -- https://bugs.ruby-lang.org/ Unsubscribe: