From: "zenspider (Ryan Davis)" <noreply@...>
Date: 2021-12-29T05:24:47+00:00
Subject: [ruby-core:106895] [Ruby master Bug#18449] Bug in 3.1 regexp literals with \c

Issue #18449 has been updated by zenspider (Ryan Davis).


I was just coming back to point at:

```
Jeremy Evans: Fix handling of control/meta escapes in literal regexps [Wed May 12 12:37:55 2021 -0700 (8 months ago)]
```

found in https://github.com/ruby/ruby/commit/11ae581a4a7f5d5f5ec6378872eab8f25381b1b9

----------------------------------------
Bug #18449: Bug in 3.1 regexp literals with \c
https://bugs.ruby-lang.org/issues/18449#change-95712

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>