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

ruby-changes:51123

From: normal <ko1@a...>
Date: Thu, 3 May 2018 10:24:14 +0900 (JST)
Subject: [ruby-changes:51123] normal:r63330 (trunk): Revert "ext/cgi/escape: preserve String subclass in result"

normal	2018-05-03 10:24:09 +0900 (Thu, 03 May 2018)

  New Revision: 63330

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63330

  Log:
    Revert "ext/cgi/escape: preserve String subclass in result"
    
    This reverts commit 6afea14043b0c0e603f26c89ae0d043f65852668 r63328
    I misread the original bug report and got results flipped.

  Modified files:
    trunk/ext/cgi/escape/escape.c
    trunk/test/cgi/test_cgi_util.rb
Index: ext/cgi/escape/escape.c
===================================================================
--- ext/cgi/escape/escape.c	(revision 63329)
+++ ext/cgi/escape/escape.c	(revision 63330)
@@ -59,7 +59,7 @@ optimized_escape_html(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L59
 	  case '<':
 	  case '>':
 	    if (!dest) {
-		dest = rb_str_new_with_class(str, 0, 0);
+		dest = rb_str_buf_new(len);
 	    }
 
 	    rb_str_cat(dest, cstr + beg, i - beg);
@@ -151,7 +151,7 @@ optimized_unescape_html(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L151
 	    i += clen;
 	    if (overflow || cc >= charlimit || cstr[i] != ';') continue;
 	    if (!dest) {
-		dest = rb_str_new_with_class(str, 0, 0);
+		dest = rb_str_buf_new(len);
 	    }
 	    rb_str_cat(dest, cstr + beg, plen);
 	    if (charlimit > 256) {
@@ -168,7 +168,7 @@ optimized_unescape_html(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L168
 	    continue;
 	}
 	if (!dest) {
-	    dest = rb_str_new_with_class(str, 0, 0);
+	    dest = rb_str_buf_new(len);
 	}
 	rb_str_cat(dest, cstr + beg, plen);
 	rb_str_cat(dest, &c, 1);
@@ -219,7 +219,7 @@ optimized_escape(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L219
 	const unsigned char c = (unsigned char)cstr[i];
 	if (!url_unreserved_char(c)) {
 	    if (!dest) {
-		dest = rb_str_new_with_class(str, 0, 0);
+		dest = rb_str_buf_new(len);
 	    }
 
 	    rb_str_cat(dest, cstr + beg, i - beg);
@@ -278,7 +278,7 @@ optimized_unescape(VALUE str, VALUE enco https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L278
 	}
 
 	if (!dest) {
-	    dest = rb_str_new_with_class(str, 0, 0);
+	    dest = rb_str_buf_new(len);
 	}
 
 	rb_str_cat(dest, cstr + beg, i - beg);
Index: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 63329)
+++ test/cgi/test_cgi_util.rb	(revision 63330)
@@ -197,25 +197,4 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L197
     assert_equal('&lt;BR&gt;<A HREF="url"></A>', unescape_element(escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG"))
     assert_equal('&lt;BR&gt;<A HREF="url"></A>', unescape_element(escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"]))
   end
-
-  def test_escape_string_subclass
-    sc = Class.new(String).freeze
-    str = sc.new('>')
-    msg = '[ruby-core:86847] [Bug #14732]'
-    assert_not_instance_of String, str
-
-    html = escapeHTML(str)
-    assert_instance_of sc, html, msg
-    assert_equal '&gt;', html
-    orig = unescapeHTML(html)
-    assert_instance_of sc, orig, msg
-    assert_equal '>', orig
-
-    url = escape(str)
-    assert_instance_of sc, url, msg
-    assert_equal '%3E', url
-    orig = unescape(url)
-    assert_instance_of sc, orig, msg
-    assert_equal '>', orig
-  end
 end

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

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