Forum: Ruby-core [ruby-trunk - Bug #8205][Open] Regexp.union behavior and Regexp.try_convert

D5d3cde0a42720acaa0cf87f2da3c32b?d=identicon&s=25 avyy (Alexander Yunin) (Guest)
on 2013-04-02 16:22
(Received via mailing list)
Issue #8205 has been reported by avyy (Alexander Yunin).

----------------------------------------
Bug #8205: Regexp.union behavior and Regexp.try_convert
https://bugs.ruby-lang.org/issues/8205

Author: avyy (Alexander Yunin)
Status: Open
Priority: Low
Assignee:
Category:
Target version:
ruby -v: 1.9.3p374


Hi! Why Regexp.union('/../') trying to convert string with directly call
rb_check_regexp_type(arg) (re.c:3139) instead of rb_reg_s_try_convert
(re.c:3122)? I think second variant would be more correct, and i would
be able to rewrite Regexp.try_convert in my code for changing behavior
as i need.
For example: i have the code where was implemented String#to_regexp
which breaks default behavior of Regexp.union and i got incorrect
regexp. But i can't (for some reasons) to rewrite to_regexp method. Yes,
stupid example, but it's real situation.
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-04-13 16:45
(Received via mailing list)
Issue #8205 has been updated by nagachika (Tomoyuki Chikanaga).

Status changed from Open to Feedback

Hello,

Could you show us a reproducive code or a testcase?
----------------------------------------
Bug #8205: Regexp.union behavior and Regexp.try_convert
https://bugs.ruby-lang.org/issues/8205#change-38517

Author: avyy (Alexander Yunin)
Status: Feedback
Priority: Low
Assignee:
Category:
Target version:
ruby -v: 1.9.3p374


Hi! Why Regexp.union('/../') trying to convert string with directly call
rb_check_regexp_type(arg) (re.c:3139) instead of rb_reg_s_try_convert
(re.c:3122)? I think second variant would be more correct, and i would
be able to rewrite Regexp.try_convert in my code for changing behavior
as i need.
For example: i have the code where was implemented String#to_regexp
which breaks default behavior of Regexp.union and i got incorrect
regexp. But i can't (for some reasons) to rewrite to_regexp method. Yes,
stupid example, but it's real situation.
D5d3cde0a42720acaa0cf87f2da3c32b?d=identicon&s=25 avyy (Alexander Yunin) (Guest)
on 2013-09-04 14:58
(Received via mailing list)
Issue #8205 has been updated by avyy (Alexander Yunin).


Hello,

Bug description is incorrect, sorry. Now i want to say that
implementation of String#to_regexp can breaks behavior of Regexp::union.

class String
  def to_regexp
    /regexp/
  end
end
Regexp.union('/some_regexp/') #=> /regexp/

And it's not documented now.

----------------------------------------
Bug #8205: Regexp.union behavior and Regexp.try_convert
https://bugs.ruby-lang.org/issues/8205#change-41611

Author: avyy (Alexander Yunin)
Status: Feedback
Priority: Low
Assignee:
Category:
Target version:
ruby -v: 1.9.3p374
Backport:


Hi! Why Regexp.union('/../') trying to convert string with directly call
rb_check_regexp_type(arg) (re.c:3139) instead of rb_reg_s_try_convert
(re.c:3122)? I think second variant would be more correct, and i would
be able to rewrite Regexp.try_convert in my code for changing behavior
as i need.
For example: i have the code where was implemented String#to_regexp
which breaks default behavior of Regexp.union and i got incorrect
regexp. But i can't (for some reasons) to rewrite to_regexp method. Yes,
stupid example, but it's real situation.
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-09-12 18:43
(Received via mailing list)
Issue #8205 has been updated by nagachika (Tomoyuki Chikanaga).

Category set to doc
Status changed from Feedback to Assigned
Assignee set to zzak (Zachary Scott)
Target version set to current: 2.1.0

Hello, avyy.

That makes sense.
I think it's spec that Regexp.union internally convert arguments with
to_regexp, but it is undocumented behavior. I think it's a documentation
issue.
----------------------------------------
Bug #8205: Regexp.union behavior and Regexp.try_convert
https://bugs.ruby-lang.org/issues/8205#change-41776

Author: avyy (Alexander Yunin)
Status: Assigned
Priority: Low
Assignee: zzak (Zachary Scott)
Category: doc
Target version: current: 2.1.0
ruby -v: 1.9.3p374
Backport:


Hi! Why Regexp.union('/../') trying to convert string with directly call
rb_check_regexp_type(arg) (re.c:3139) instead of rb_reg_s_try_convert
(re.c:3122)? I think second variant would be more correct, and i would
be able to rewrite Regexp.try_convert in my code for changing behavior
as i need.
For example: i have the code where was implemented String#to_regexp
which breaks default behavior of Regexp.union and i got incorrect
regexp. But i can't (for some reasons) to rewrite to_regexp method. Yes,
stupid example, but it's real situation.
This topic is locked and can not be replied to.