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

ruby-changes:4750

From: ko1@a...
Date: Wed, 30 Apr 2008 21:41:15 +0900 (JST)
Subject: [ruby-changes:4750] seki - Ruby:r16244 (trunk): ERB::Util#url_encode bug fix. Reported by rubikitch.

seki	2008-04-30 21:40:52 +0900 (Wed, 30 Apr 2008)

  New Revision: 16244

  Modified files:
    trunk/ChangeLog
    trunk/lib/erb.rb
    trunk/test/erb/test_erb.rb

  Log:
     [ruby-dev:34497] ERB::Util#url_encode bug fix. Reported by rubikitch.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16244&r2=16243&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/erb/test_erb.rb?r1=16244&r2=16243&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/erb.rb?r1=16244&r2=16243&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16243)
+++ ChangeLog	(revision 16244)
@@ -1,3 +1,10 @@
+Wed Apr 30 21:36:40 2008  Masatoshi SEKI  <m_seki@m...>
+
+	* lib/erb.rb (url_encode): [ruby-dev:34497] ERB::Util#url_encode
+	  bug fix. Reported by rubikitch.
+
+	* test/erb/test_erb.rb: ditto
+
 Wed Apr 30 20:11:36 2008  James Edward Gray II  <jeg2@r...>
 
 	* lib/net/telnet.rb:  Fixing a bug where line endings would not be properly
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 16243)
+++ lib/erb.rb	(revision 16244)
@@ -799,7 +799,9 @@
     # 	Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
     #
     def url_encode(s)
-      s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
+      s.to_s.dup.force_encoding("ASCII-8BIT").gsub(/[^a-zA-Z0-9_\-.]/n) {
+        sprintf("%%%02X", $&.unpack("C")[0])
+      }
     end
     alias u url_encode
     module_function :u
Index: test/erb/test_erb.rb
===================================================================
--- test/erb/test_erb.rb	(revision 16243)
+++ test/erb/test_erb.rb	(revision 16244)
@@ -44,15 +44,15 @@
     @erb = ERB
   end
 
-  def test_01
-    _test_01(nil)
-    _test_01(0)
-    _test_01(1)
-    _test_01(2)
-    _test_01(3)
+  def test_core
+    _test_core(nil)
+    _test_core(0)
+    _test_core(1)
+    _test_core(2)
+    _test_core(3)
   end
 
-  def _test_01(safe)
+  def _test_core(safe)
     erb = @erb.new("hello")
     assert_equal(erb.result, "hello")
 
@@ -157,14 +157,14 @@
     assert_equal(ans, erb.result)
   end
 
-  def test_02_safe_04
+  def test_safe_04
     erb = @erb.new('<%=$SAFE%>', 4)
     assert_equal(erb.result(TOPLEVEL_BINDING.taint), '4')
   end
 
   class Foo; end
 
-  def test_03_def_class
+  def test_def_class
     erb = @erb.new('hello')
     cls = erb.def_class
     assert_equal(Object, cls.superclass)
@@ -177,7 +177,7 @@
     assert(cls.new.respond_to?('erb'))
   end
 
-  def test_04_percent
+  def test_percent
     src = <<EOS
 %n = 1
 <%= n%>
@@ -220,7 +220,7 @@
 
   class Bar; end
 
-  def test_05_def_method
+  def test_def_method
     assert(! Bar.new.respond_to?('hello'))
     Bar.module_eval do
       extend ERB::DefMethod
@@ -237,7 +237,7 @@
     assert(Bar.new.respond_to?('hello_world'))    
   end
 
-  def test_06_escape
+  def test_escape
     src = <<EOS
 1.<%% : <%="<%%"%>
 2.%%> : <%="%%>"%>
@@ -274,7 +274,7 @@
     assert_equal(ans, ERB.new(src, nil, '%').result)
   end
 
-  def test_07_keep_lineno
+  def test_keep_lineno
     src = <<EOS
 Hello, 
 % x = "World"
@@ -378,7 +378,7 @@
     end
   end
 
-  def test_08_explicit
+  def test_explicit
     src = <<EOS
 <% x = %w(hello world) -%>
 NotSkip <%- y = x -%> NotSkip
@@ -410,4 +410,12 @@
    assert_equal(ans, ERB.new(src, nil, '-').result)
    assert_equal(ans, ERB.new(src, nil, '-%').result)
   end
+
+  def test_url_encode
+    assert_equal("Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide",
+                 ERB::Util.url_encode("Programming Ruby:  The Pragmatic Programmer's Guide"))
+
+    assert_equal("%A5%B5%A5%F3%A5%D7%A5%EB",
+                 ERB::Util.url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding("EUC-JP")))
+  end
 end

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

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