[ruby-dev:31786] rstripがstripしすぎる

From: Kouhei Sutou <kou@...>
Date: 2007-09-15 03:56:24 UTC
List: ruby-dev #31786
須藤です。

途中に空白はあるが、最後は空白で終わっていない文字列を渡すと、
rstripが必要以上にstripします。

  % /tmp/local/bin/ruby -v -e 'p "a b".rstrip'
  ruby 1.9.0 (2007-09-14 patchlevel 0) [x86_64-linux]
  "a"


Index: string.c
===================================================================
--- string.c    (リビジョン 13445)
+++ string.c    (作業コピー)
@@ -4373,6 +4373,7 @@
        }
        s += rb_enc_codelen(cc, enc);
     }
+    if (!space_seen) t = s;
     if (t < e) {
        rb_str_modify(str);
        STR_SET_LEN(str, t-RSTRING_PTR(str));


In This Thread

Prev Next