Project

General

Profile

Actions

Bug #18449

closed

Bug in 3.1 regexp literals with \c

Added by zenspider (Ryan Davis) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
3.1.0
Backport:
[ruby-core:106888]

Description

This file passes on 2.7, 3.0, and fails (if you remove the skip line) on 3.1:

#!/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/

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #14367: Wrong interpretation of backslash C in regexp literalsClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0