Project

General

Profile

Actions

Bug #8151

closed

Duplicate character class warning

Added by tenderlovemaking (Aaron Patterson) about 11 years ago. Updated about 11 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
Backport:
[ruby-core:53649]

Description

I get a duplicate character class warning, but I think it's a bug. Here is the example code:

def embed exp, depth
  return exp if depth == 0
  embed(/#{exp}/, depth - 1)
end

3.times { |i|
  puts "DEPTH #{i + 1}"
  embed(/[a-z\u{7b}-\u{7d}]/, i + 1)
}

At depth = 1, there is no warning, but greater than 1, I get a duplicate character class warning. I don't think the character class overlaps, so there should never be a warning.

Updated by mame (Yusuke Endoh) about 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)

Interestingly, this seems to be a bug of Regexp#to_s, not a regexp creation.

re = /(?:[\u{33}])/
p re #=> /(?:[\u{33}])/

puts re.to_s
#=> warning: character class has duplicated range: /[\u{33}]/
#=> (?-mix:[\u{33}])

As I recall, akr created round trip to_s.

--
Yusuke Endoh

Updated by akr (Akira Tanaka) about 11 years ago

  • Assignee changed from akr (Akira Tanaka) to naruse (Yui NARUSE)

The warning is proposed by [ruby-core:24593] [Feature #1831] (2009-07-29) and committed by naruse.

It is seven years later than my Regexp#to_s [ruby-dev:16951] (2002-04-18)

It seems this issue is better to assign naruse.

Actions #3

Updated by naruse (Yui NARUSE) about 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40063.
Aaron, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • re.c (rb_reg_to_s): suppress duplicated charclass warning.
    Regexp#to_s suppress extra its whole regexp options by calling
    onig_new with its source, but it doesn't call rb_reg_preprocess.
    Therefore its Unicode escapes (\u{XXXX}) are given as is,
    and it may cause duplicated charclass warning for example
    "[\u{33}]" (3 is duplicated) or "[\u{a}\u{b}]" (u is duplicated).
    [ruby-core:53649] [Bug #8151]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0