Bug #8151
closedDuplicate character class warning
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 mame@tsg.ne.jp
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.
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]