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

ruby-changes:23163

From: nobu <ko1@a...>
Date: Mon, 2 Apr 2012 10:34:22 +0900 (JST)
Subject: [ruby-changes:23163] nobu:r35213 (trunk): * string.c (rb_str_start_with, rb_str_end_with): raise an error if

nobu	2012-04-02 10:34:11 +0900 (Mon, 02 Apr 2012)

  New Revision: 35213

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

  Log:
    * string.c (rb_str_start_with, rb_str_end_with): raise an error if
      an argument is not convertible to a String.
      [ruby-core:40623][Bug #5536]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
    trunk/test/ruby/test_string.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35212)
+++ ChangeLog	(revision 35213)
@@ -1,3 +1,9 @@
+Mon Apr  2 10:34:00 2012  eregon  <eregontp@g...>
+
+	* string.c (rb_str_start_with, rb_str_end_with): raise an error if
+	  an argument is not convertible to a String.
+	  [ruby-core:40623][Bug #5536]
+
 Mon Apr  2 03:35:25 2012  NARUSE, Yui  <naruse@r...>
 
 	* lib/webrick/server.rb (WEBrick::GenericServer): close socket only if
Index: string.c
===================================================================
--- string.c	(revision 35212)
+++ string.c	(revision 35213)
@@ -7197,8 +7197,8 @@
     int i;
 
     for (i=0; i<argc; i++) {
-	VALUE tmp = rb_check_string_type(argv[i]);
-	if (NIL_P(tmp)) continue;
+	VALUE tmp = argv[i];
+	StringValue(tmp);
 	rb_enc_check(str, tmp);
 	if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue;
 	if (memcmp(RSTRING_PTR(str), RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)
@@ -7222,8 +7222,8 @@
     rb_encoding *enc;
 
     for (i=0; i<argc; i++) {
-	VALUE tmp = rb_check_string_type(argv[i]);
-	if (NIL_P(tmp)) continue;
+	VALUE tmp = argv[i];
+	StringValue(tmp);
 	enc = rb_enc_check(str, tmp);
 	if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue;
 	p = RSTRING_PTR(str);
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 35212)
+++ test/ruby/test_string.rb	(revision 35213)
@@ -659,6 +659,15 @@
     assert(!S("not").empty?)
   end
 
+  def test_end_with?
+    assert_send([S("hello"), :end_with?, S("llo")])
+    assert_not_send([S("hello"), :end_with?, S("ll")])
+    assert_send([S("hello"), :end_with?, S("el"), S("lo")])
+
+    bug5536 = '[ruby-core:40623]'
+    assert_raise(TypeError, bug5536) {S("str").end_with? :not_convertible_to_string}
+  end
+
   def test_eql?
     a = S("hello")
     assert(a.eql?(S("hello")))
@@ -1207,6 +1216,15 @@
     assert_nil(a.squeeze!)
   end
 
+  def test_start_with?
+    assert_send([S("hello"), :start_with?, S("hel")])
+    assert_not_send([S("hello"), :start_with?, S("el")])
+    assert_send([S("hello"), :start_with?, S("el"), S("he")])
+
+    bug5536 = '[ruby-core:40623]'
+    assert_raise(TypeError, bug5536) {S("str").start_with? :not_convertible_to_string}
+  end
+
   def test_strip
     assert_equal(S("x"), S("      x        ").strip)
     assert_equal(S("x"), S(" \n\r\t     x  \t\r\n\n      ").strip)
@@ -1774,10 +1792,6 @@
     assert_nil(l.slice!(/\A.*\n/), "[ruby-dev:31665]")
   end
 
-  def test_end_with?
-    assert("abc".end_with?("c"))
-  end
-
   def test_times2
     s1 = ''
     100.times {|n|

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

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