ERB::Util#url_encode bug fix

e$B$k$S$-$A$G$9!#e(B

ERB::Util#url_encodee$B$,F|K\8lJ8;[email protected]$7$$7k2L$K$J$i$J$$%P%[email protected]$7$^$7$?!#e(B

Index: lib/erb.rb

— lib/erb.rb (revision 16174)
+++ lib/erb.rb (working copy)
@@ -799,7 +799,8 @@
#
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 16174)
    +++ test/erb/test_erb.rb (working copy)
    @@ -411,3 +411,18 @@
    assert_equal(ans, ERB.new(src, nil, ‘-%’).result)
    end
    end

+class TestERBUtil < Test::Unit::TestCase

  • include ERB::Util
  • def test_01

assert_equal(“Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide”,

  •  url_encode("Programming Ruby:  The Pragmatic Programmer's 
    

Guide"))

  • end
  • def test_02
  • assert_equal("%A5%B5%A5%F3%A5%D7%A5%EB",

url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding(“EUC-JP”)))

  • end

+end

e$B?\F#$G$9!#e(B

e$BK\Bj$H4X78$J$$$H$3$m$J$s$G$9$,!#!#!#e(B

In [email protected]
“[ruby-dev:34497] ERB::Util#url_encode bug fix” on Wed, 23 Apr 2008
22:30:51 +0900,
[email protected] wrote:

ERB::Util#url_encodee$B$,F|K\8lJ8;[email protected]$7$$7k2L$K$J$i$J$$%P%[email protected]$7$^$7$?!#e(B

  • include ERB::Util

+end

e$B$*$=$i$/!“e(BTestERBCoree$B$,e(B01e$B$H$+$D$$$F$$$?$N$G$=$&[email protected]$H;W$&e(B
e$B$N$G$9$,!”$b$&>/$70UL#$N$"$k%a%=%C%IL>$r;H$C$?J}$,$h$$5$$,$7e(B
e$B$^$9!#!Je(BTestERBCoree$B$N%a%=%C%IL>$OD>$7$?J}$,$h$$$H;W$&!#!Ke(B

e$B$*$=$i$/!"$A$g$C$HIT;W5D$J%$%s%G%s%H$r$7$F$$$k$N$OJ8;zNs$N0Le(B
e$BCV$rB7$([email protected]$H;W$&$N$G$9$,!"?7$7$/e(Basserte$B$J$s$H$+$rDj5Ae(B
e$B$7$FIaDL$N%$%s%G%s%H$r$7$?J}$,$h$$5$$,$7$^$9!#e(B

def assert_url_encode(expected, input)
assert_equal(expected, url_encode(input))
end

def test_XXX
assert_url_encode("%A5%B5%A5%F3%A5%D7%A5%EB",
“\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB”.force_encoding(“EUC-JP”))
end

From: Kouhei S. [email protected]
Subject: [ruby-dev:34498] Re: ERB::Util#url_encode bug fix
Date: Wed, 23 Apr 2008 23:06:38 +0900

e$B$*$=$i$/!“e(BTestERBCoree$B$,e(B01e$B$H$+$D$$$F$$$?$N$G$=$&[email protected]$H;W$&e(B
e$B$N$G$9$,!”$b$&>/$70UL#$N$"$k%a%=%C%IL>$r;H$C$?J}$,$h$$5$$,$7e(B
e$B$^$9!#!Je(BTestERBCoree$B$N%a%=%C%IL>$OD>$7$?J}$,$h$$$H;W$&!#!Ke(B

e$B$=$&$G$9$M!#e(B

def test_XXX
assert_url_encode("%A5%B5%A5%F3%A5%D7%A5%EB",
“\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB”.force_encoding(“EUC-JP”))
end

e$BIT;W5D$J!J!)!K%$%s%G%s%H$J$N$Oe(BEmacse$B$Ge(B
(setq ruby-deep-indent-paren-style nil)
[email protected]_Dj$7$F$$$k$?$a$G$9!#e(B
(setq ruby-deep-indent-paren-style t)
e$B$G>e$N$h$&$J%$%s%G%s%H$K$J$j$^$9!#e([email protected]_Dj$7$F$$$k$N$Oe(B

Foo::Bar::Baz::Hoge::hoge( :x => 1,
:y => 2)

e$B$_$?$$$K%$%s%G%s%H$,?<$/$J$C$F$7$^$&$+$i$G$9!#e(B

e$B;29M!'e(Bhttp://d.hatena.ne.jp/gan2/20070621/1182441886

Rubye$BK\BN$N%3!<%G%#%s%05,Ls$G%$%s%G%s%H$N$d$jJ}$O7h$^$C$F$$$k$N$G$7$g$&$+!)e(B

e$B?\F#$G$9!#e(B

In [email protected]
“[ruby-dev:34499] Re: ERB::Util#url_encode bug fix” on Wed, 23 Apr
2008 23:36:10 +0900,
[email protected] wrote:

e$B;29M!'e(Bhttp://d.hatena.ne.jp/gan2/20070621/1182441886

e$B%j%s%/@h$K$"$k$h$&$K$3$le(B

Foo::Bar::Baz::Hoge::hoge( :x => 1,
:y => 2)
e$B$r$3$&e(B

Foo::Bar::Baz::Hoge::hoge(
:x => 1,
:y => 2
)

e$B$7$?$$$J$i$^[email protected]$o$+$k$N$G$9$,!J;d$O7y$G$9$,!K!"$3$&e(B

Foo::Bar::Baz::Hoge::hoge(:x => 1,
:y => 2)

e$B$9$k$N$O$^$k$GM}2r$G$-$J$$$N$G$9$,!#!#!#e(B

e$B$J$N$G!"$3$l$b5$;}$A0-$$!#e(B

- 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]) }

e$B;d$N;}[email protected]$G$O!"%$%s%G%s%H$,?<$/$J$k$N$O$=$3$G$d$m$&$H$7$F$$$ke(B
e$B$3$H$,B?$9$.$k7Y9p$J$N$G!"%$%s%G%s%H$r8:$i$7$F$4$^$+$5$J$$$Ge(B
e$B$=$3$rD>$7$?J}$,$h$$$H;W$C$F$$$^$9!#Nc$($P!"$3$NNc$G$O;d$O$3e(B
e$B$s$JIw$K$9$k$H;W$$$^$9!#e(B

def do_hoge(options)
Foo::Bar::Baz::Hoge::hoge(options)
end

do_hoge(:x => 1,
:y => 2)

e$BK\Ev$Oe(Bdo_hoge(:x => 1, :y => 2)e$B$K$7$^$9$,!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs