Project

General

Profile

Actions

Bug #592

closed

String#rstrip sometimes strips NULLs, sometimes doesn't - encoding dependent

Added by mike (Michael Selig) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Backport:
[ruby-core:18844]

Description

=begin
ruby -ve 'p "abc \x00\x00".rstrip'
ruby 1.9.0 (2008-09-24 revision 19507) [i686-linux]
"abc"

but:
ruby -ve 'p "\u0635abc \x00\x00".rstrip'
ruby 1.9.0 (2008-09-24 revision 19507) [i686-linux]
"صabc \x00\x00"
=end

Actions #1

Updated by usa (Usaku NAKAMURA) over 15 years ago

=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, 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;

  enc = STR_ENC_GET(str);
  • 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)) {

  • /* remove trailing spaces or '\0's /
    while (s < t && (
    (t-1) == '\0' || rb_enc_isspace(*(t-1), enc))) t--;
    }
    else {
    char *tp;

      while ((tp = rb_enc_prev_char(s, t, e, enc)) != NULL) {
    
  •  if (!rb_enc_isspace(rb_enc_codepoint(tp, e, enc), enc)) break;
    
  •  unsigned int c = rb_enc_codepoint(tp, e, enc);
    
  •  if (c && !rb_enc_isspace(c, enc)) break;
     t = tp;
    
    }
    }

    Regards,
    --
    U.Nakamura

=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 15 years ago

=begin
Hi,

In message "Re: [ruby-core:18851] Re: [Bug #592] String#rstrip sometimes strips NULLs, sometimes doesn't - encoding dependent"
on Wed, 24 Sep 2008 19:43:54 +0900, "U.Nakamura" writes:

|In message "[ruby-core:18844] [Bug #592] String#rstrip sometimes strips NULLs, sometimes doesn't - encoding dependent"
| on Sep.24,2008 17:04:11, 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?

I made almost identical patch. Please commit.

						matz.

=end

Actions #3

Updated by usa (Usaku NAKAMURA) over 15 years ago

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

=begin
Applied in changeset r19529.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0