aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--lib/erb.rb4
-rw-r--r--test/erb/test_erb.rb36
3 files changed, 32 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index c77ba97037..ca79ffbb17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Apr 30 21:36:40 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
+
+ * 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@ruby-lang.org>
* lib/net/telnet.rb: Fixing a bug where line endings would not be properly
diff --git a/lib/erb.rb b/lib/erb.rb
index 42b3930c10..fade2c72ba 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -799,7 +799,9 @@ class ERB
# 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
diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb
index b2099af6b8..aac33863d4 100644
--- a/test/erb/test_erb.rb
+++ b/test/erb/test_erb.rb
@@ -44,15 +44,15 @@ class TestERBCore < Test::Unit::TestCase
@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 @@ EOS
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 @@ EOS
assert(cls.new.respond_to?('erb'))
end
- def test_04_percent
+ def test_percent
src = <<EOS
%n = 1
<%= n%>
@@ -220,7 +220,7 @@ EOS
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 @@ EOS
assert(Bar.new.respond_to?('hello_world'))
end
- def test_06_escape
+ def test_escape
src = <<EOS
1.<%% : <%="<%%"%>
2.%%> : <%="%%>"%>
@@ -274,7 +274,7 @@ EOS
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 @@ EOS
end
end
- def test_08_explicit
+ def test_explicit
src = <<EOS
<% x = %w(hello world) -%>
NotSkip <%- y = x -%> NotSkip
@@ -410,4 +410,12 @@ EOS
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