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

ruby-changes:2777

From: ko1@a...
Date: 17 Dec 2007 18:08:44 +0900
Subject: [ruby-changes:2777] matz - Ruby:r14268 (trunk): * string.c (rb_str_index): check if substring is broken.

matz	2007-12-17 18:08:27 +0900 (Mon, 17 Dec 2007)

  New Revision: 14268

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_knownbug.rb
    trunk/encoding.c
    trunk/string.c

  Log:
    * string.c (rb_str_index): check if substring is broken.
    
    * string.c (rb_str_rindex): ditto.
    
    * string.c (rb_str_succ): should carry over.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=14268&r2=14267
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14268&r2=14267
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=14268&r2=14267
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14268&r2=14267

Index: encoding.c
===================================================================
--- encoding.c	(revision 14267)
+++ encoding.c	(revision 14268)
@@ -553,7 +553,8 @@
     return n;
 }
 
-int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
+int
+rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
 {
     int c, l;
     if (e <= p)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14267)
+++ ChangeLog	(revision 14268)
@@ -1,3 +1,11 @@
+Mon Dec 17 17:50:30 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* string.c (rb_str_index): check if substring is broken.
+
+	* string.c (rb_str_rindex): ditto.
+
+	* string.c (rb_str_succ): should carry over.
+
 Mon Dec 17 17:47:26 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (encs): new target to compile external encodings.
Index: bootstraptest/test_knownbug.rb
===================================================================
--- bootstraptest/test_knownbug.rb	(revision 14267)
+++ bootstraptest/test_knownbug.rb	(revision 14268)
@@ -219,12 +219,12 @@
   "\xa1\xa2\xa3\xa4".force_encoding("euc-jp").include?("\xa3".force_encoding("euc-jp"))
 }
 
-assert_equal 'nil', %q{
-  "\xa1\xa2\xa3\xa4".force_encoding("euc-jp").index("\xa3".force_encoding("euc-jp"))
+assert_equal 'ok', %q{
+  "\xa1\xa2\xa3\xa4".force_encoding("euc-jp").index("\xa3".force_encoding("euc-jp")) or :ok
 }
 
-assert_equal 'nil', %q{
-  "\xa1\xa2\xa3\xa4".force_encoding("euc-jp").rindex("\xa3".force_encoding("euc-jp"))
+assert_equal 'ok', %q{
+  "\xa1\xa2\xa3\xa4".force_encoding("euc-jp").rindex("\xa3".force_encoding("euc-jp")) or :ok
 }
 
 assert_equal 'false', %q{
Index: string.c
===================================================================
--- string.c	(revision 14267)
+++ string.c	(revision 14268)
@@ -94,6 +94,7 @@
 
 #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
 #define IS_7BIT(str) (ENC_CODERANGE(str) == ENC_CODERANGE_7BIT)
+#define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
 
 VALUE rb_fs;
 
@@ -1443,6 +1444,9 @@
     rb_encoding *enc;
 
     enc = rb_enc_check(str, sub);
+    if (is_broken_string(sub)) {
+	return -1;
+    }
     len = str_strlen(str, enc);
     slen = str_strlen(sub, enc);
     if (offset < 0) {
@@ -1553,6 +1557,9 @@
     int asc = IS_7BIT(str);
 
     enc = rb_enc_check(str, sub);
+    if (is_broken_string(sub)) {
+	return -1;
+    }
     len = str_strlen(str, enc);
     slen = str_strlen(sub, enc);
     /* substring longer than string */
@@ -1863,7 +1870,7 @@
     if (c == -1) {		/* str contains no alnum */
 	c = '\001';
 	s = e;
-	while ((s = rb_enc_prev_char(sbeg, e, enc)) != 0) {
+	while ((s = rb_enc_prev_char(sbeg, s, enc)) != 0) {
 	    if (cc == 0) cc = rb_enc_codepoint(s, e, enc);
 	    cc += 1;
 	    l = rb_enc_mbcput(cc, carry, enc);

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

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