=begin
Hello,
In message "[ruby-core:18844] [Bug #592 ] String#rstrip sometimes strips NULLs, sometimes doesn't - encoding dependent"
on Sep.24,2008 17:04:11, redmine@ruby-lang.org wrote:
Bug #592 : String#rstrip sometimes strips NULLs, sometimes doesn't - encoding dependent
ruby -ve 'p "\u0635abc \x00\x00".rstrip'
ruby 1.9.0 (2008-09-24 revision 19507) [i686-linux]
"?abc \x00\x00"
There is a patch.
Matz, is this ok?
Index: string.c¶
--- string.c (revision 19526)
+++ string.c (working copy)
@@ -5856,19 +5856,23 @@ rb_str_rstrip_bang(VALUE str)
char *s, *t, *e;
if (rb_enc_dummy_p(enc)) {
rb_raise(rb_eEncCompatError, "incompatible encoding with this operation: %s", rb_enc_name(enc));
}
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return Qnil;
t = e = RSTRING_END(str);
/* remove trailing spaces or '\0's */
if (single_byte_optimizable(str)) {
unsigned int c = rb_enc_codepoint(tp, e, enc);
if (c && !rb_enc_isspace(c, enc)) break;
t = tp;
}
}
Regards,
--
U.Nakamura usa@garbagecollect.jp
=end