Revision: 3795 http://trac.macosforge.org/projects/ruby/changeset/3795 Author: lsansonetti@apple.com Date: 2010-03-17 22:02:24 -0700 (Wed, 17 Mar 2010) Log Message: ----------- fix some bugs in #index Modified Paths: -------------- MacRuby/trunk/string.c Modified: MacRuby/trunk/string.c =================================================================== --- MacRuby/trunk/string.c 2010-03-18 03:49:19 UTC (rev 3794) +++ MacRuby/trunk/string.c 2010-03-18 05:02:24 UTC (rev 3795) @@ -1887,7 +1887,7 @@ if (pos < 0) { pos += len; } - if (pos < 0 || pos >= len) { + if (pos < 0) { if (TYPE(sub) == T_REGEXP) { rb_backref_set(Qnil); } @@ -1900,6 +1900,9 @@ switch (TYPE(sub)) { case T_REGEXP: + if (pos > len) { + return Qnil; + } pos = rb_reg_search(sub, self, pos, false); break; @@ -1907,8 +1910,13 @@ StringValue(sub); // fall through case T_STRING: - pos = str_index_for_string(RSTR(self), str_need_string(sub), - pos, -1, false, true); + if (pos == len && rb_str_chars_len(sub) == 0) { + // Do nothing... RubySpec compliance... + } + else { + pos = str_index_for_string(RSTR(self), str_need_string(sub), + pos, -1, false, true); + } break; }
participants (1)
-
source_changes@macosforge.org