Bug #3599
Incorrect Regexp inspect for ASCII-8BIT String
| Status: | Closed | Start date: | 07/22/2010 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 100% |
|
| Category: | core | |||
| Target version: | 2.0.0 | |||
| ruby -v: | ruby 1.9.3dev (2010-07-22 trunk 28707) [i686-linux] |
Description
irb(main):001:0> a = Regexp.new("\xF1\xF2\xF3".force_encoding('ASCII-8BIT'))
=> /\xF1/
irb(main):002:0> puts a.inspect
/\xF1/
=> nil
irb(main):003:0> "\xF0\xF1".force_encoding('ASCII-8BIT') =~ a
=> nil
irb(main):004:0> a.source
=> "\xF1\xF2\xF3"
irb(main):005:0> "\xF0\xF1\xF2\xF3".force_encoding('ASCII-8BIT') =~ a
=> 1
Associated revisions
* re.c (rb_reg_expr_str): fix broken Regexp#inspect when it
is ASCII-8BIT and non-ASCII character.
The length of character should be from original byte string.
[ruby-core:31431]
History
Updated by phasis68 (Heesob Park) almost 2 years ago
Here is a simple patch for this bug.
--- re.c 2010-07-22 16:12:01.536788151 +0900
+++ re.c.new 2010-07-22 16:13:15.229038356 +0900
@@ -373,7 +373,8 @@
int l;
if (resenc) {
unsigned int c = rb_enc_mbc_to_codepoint(p, pend, enc);
- l = rb_str_buf_cat_escaped_char(str, c, unicode_p);
+ rb_str_buf_cat_escaped_char(str, c, unicode_p);
+ l = clen;
}
else {
l = mbclen(p, pend, enc);
Updated by naruse (Yui NARUSE) almost 2 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r28715. Heesob, thank you for reporting this issue. Your contribution to Ruby is greatly appreciated. May Ruby be with you.