[前][次][番号順一覧][スレッド一覧]

ruby-changes:8005

From: usa <ko1@a...>
Date: Wed, 24 Sep 2008 23:01:56 +0900 (JST)
Subject: [ruby-changes:8005] Ruby:r19529 (trunk): * string.c (rb_str_rstrip_bang): raise exception when the encoding of

usa	2008-09-24 23:01:41 +0900 (Wed, 24 Sep 2008)

  New Revision: 19529

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19529

  Log:
    * string.c (rb_str_rstrip_bang): raise exception when the encoding of
      the string is dummy.
    
    * string.c (rb_str_rstrip_bang): remove nul characters even if the
      encoding of the string is not single byte optimizable.
      fixed [ruby-core:18844], reported by Michael Selig.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19528)
+++ ChangeLog	(revision 19529)
@@ -1,6 +1,15 @@
+Wed Sep 24 22:58:18 2008  NAKAMURA Usaku  <usa@r...>
+
+	* string.c (rb_str_rstrip_bang): raise exception when the encoding of
+	  the string is dummy.
+
+	* string.c (rb_str_rstrip_bang): remove nul characters even if the
+	  encoding of the string is not single byte optimizable.
+	  fixed [ruby-core:18844], reported by Michael Selig.
+
 Wed Sep 24 19:01:45 2008  NAKAMURA Usaku  <usa@r...>
 
-	* string.c (rb_str_strip_bang): workaround for VC++8 x64.
+	* string.c (rb_str_rstrip_bang): workaround for VC++8 x64.
 
 Wed Sep 24 17:44:44 2008  Nobuyoshi Nakada  <nobu@r...>
 
Index: string.c
===================================================================
--- string.c	(revision 19528)
+++ string.c	(revision 19529)
@@ -5856,19 +5856,23 @@
     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;
 	}
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]