Project

General

Profile

Actions

Bug #14608

closed

Regexp::union and forward slashes

Added by jason.barnabe (Jason Barnabe) about 6 years ago. Updated about 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:86149]

Description

When using Regexp::union and a regular expression with a forward slash, there seem to be some inconsistencies.

# this is weird
Regexp.union(/\//, '')                  # => /(?-mix:\/)|/
Regexp.union(/\//, '') == /(?-mix:\/)|/ # => false

# here is the difference
Regexp.union(/\//, '').source           # => "(?-mix:\\/)|"
/(?-mix:\/)|/.source                    # => "(?-mix:/)|"

Previously reported at https://github.com/janosch-x/js_regex/issues/6

Updated by shevegen (Robert A. Heiler) about 6 years ago

Interesting. I would have expected them to be the same.

Would be nice if it could be explained in the official docs
too at http://ruby-doc.org/core-2.5.0/Regexp.html#method-c-union

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62779.


re.c: do not escape terminator in Regexp.union

  • re.c (rb_reg_str_with_term): change terminator.

  • re.c (rb_reg_s_union): terminator in source string does not need
    to be escaped. terminators are outside of regexp source itself.
    [ruby-core:86149] [Bug #14608]

Actions

Also available in: Atom PDF

Like0
Like0Like0