ruby-changes:2722
From: ko1@a...
Date: 13 Dec 2007 18:20:33 +0900
Subject: [ruby-changes:2722] matz - Ruby:r14213 (trunk): * string.c (rb_str_succ): should not enter infinite loop for
matz 2007-12-13 18:20:13 +0900 (Thu, 13 Dec 2007)
New Revision: 14213
Modified files:
trunk/ChangeLog
trunk/bootstraptest/test_knownbug.rb
trunk/string.c
Log:
* string.c (rb_str_succ): should not enter infinite loop for
non-ASCII, non-alphanumeric character at the bottom.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=14213&r2=14212
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14213&r2=14212
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14213&r2=14212
Index: ChangeLog
===================================================================
--- ChangeLog (revision 14212)
+++ ChangeLog (revision 14213)
@@ -13,6 +13,9 @@
* sprintf.c (rb_str_format): ditto.
+ * string.c (rb_str_succ): should not enter infinite loop for
+ non-ASCII, non-alphanumeric character at the bottom.
+
Thu Dec 13 17:03:29 2007 Nobuyoshi Nakada <nobu@r...>
* encoding.c (rb_enc_compatible): should swap encoding indexes too.
Index: bootstraptest/test_knownbug.rb
===================================================================
--- bootstraptest/test_knownbug.rb (revision 14212)
+++ bootstraptest/test_knownbug.rb (revision 14213)
@@ -127,9 +127,9 @@
s.include?("\xb0\xa3".force_encoding("euc-jp"))
}
-assert_equal 'nil', %q{
+assert_equal 'ok', %q{
s = "\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4".force_encoding("euc-jp")
- s.index("\xb3\xa3".force_encoding("euc-jp"))
+ s.index("\xb3\xa3".force_encoding("euc-jp")) or :ok
}
assert_equal 'ok', %q{
Index: string.c
===================================================================
--- string.c (revision 14212)
+++ string.c (revision 14213)
@@ -1811,6 +1811,7 @@
VALUE str;
char *sbeg, *s, *e;
int c = -1;
+ unsigned int cc = 0;
long n = 0, o = 0, l;
char carry[ONIGENC_CODE_TO_MBC_MAXLEN];
@@ -1824,7 +1825,7 @@
s = e = sbeg + RSTRING_LEN(str);
while ((s = rb_enc_prev_char(sbeg, s, enc)) != 0) {
- unsigned int cc = rb_enc_codepoint(s, e, enc);
+ cc = rb_enc_codepoint(s, e, enc);
if (rb_enc_isalnum(cc, enc)) {
if (isascii(cc)) {
if ((c = succ_char(s)) == 0) break;
@@ -1834,12 +1835,16 @@
}
n = s - sbeg;
}
+ else {
+ break;
+ }
}
if (c == -1) { /* str contains no alnum */
c = '\001';
s = e;
while ((s = rb_enc_prev_char(sbeg, e, enc)) != 0) {
- unsigned int cc = rb_enc_codepoint(s, e, enc) + 1;
+ if (cc == 0) cc = rb_enc_codepoint(s, e, enc);
+ cc += 1;
l = rb_enc_mbcput(cc, carry, enc);
if (l > 0) {
if (l == (o = e - s)) goto overlay;
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml