From: "NARUSE, Yui" Date: 2009-12-19T00:19:27+09:00 Subject: [ruby-core:27214] Re: [PATCH] fix CGI::escape to work with blocks, avoid dollar variables (2009/12/18 10:00), Gaston Ramos wrote: > El Thu, 17 de Dec de 2009, a las 09:53:37PM +0900, NARUSE, Yui dijo: >> >> I mean, your stating point: allow overriding String#gsub. >> Even if you fix cgi.rb, other problem will happen. > What other problem ? can you give me an example? I give you an example > that show you when the current version of cgi has problems. > Did you read this ticket? is other case when the current cgi doesn't work > and the problem is related with dollar variable. An example is following: class String alias :old_gsub :gsub def gsub(*args, &block) old_gsub(*args, &block) end end "abc".gsub(/b/){$'=='c' ? 'X' : $'=='C' ? 'Y' : 'Z'} #=> "aZc" "AbC".gsub(/b/){$'=='c' ? 'X' : $'=='C' ? 'Y' : 'Z'} #=> "AZC" > Or simply use my patch under Ruby 1.9 with String#gsub redefined. Following, cgi/util is current and ./lib/cgi/util is my patch. ruby19 -rcgi/util -e'CGI.escape("abc\u3042\u3044\u3046"*500000)' 13.24s user 0.29s system 99% cpu 13.542 total ruby19 -r./lib/cgi/util -e'CGI.escape("abc\u3042\u3044\u3046"*500000)' 8.73s user 0.26s system 99% cpu 8.995 total ruby19 -rcgi/util -e'CGI.escape("\u3042\u3044\u3046"*500000)' 7.02s user 3.43s system 99% cpu 10.468 total ruby19 -r./lib/cgi/util -e'CGI.escape("\u3042\u3044\u3046"*500000)' 8.48s user 0.20s system 99% cpu 8.682 total ruby19 -rcgi/util -e'CGI.escape("abc"*500000)' 0.33s user 0.04s system 99% cpu 0.367 total ruby19 -r./lib/cgi/util -e'CGI.escape("abc"*500000)' 0.23s user 0.04s system 99% cpu 0.266 total ruby19 -rcgi/util -e'100000.times{CGI.escape("abc\u3042\u3044\u3046def")}' 4.38s user 0.04s system 99% cpu 4.415 total ruby19 -r./lib/cgi/util 3.46s user 0.02s system 99% cpu 3.489 total ruby19 -rcgi/util -e's="%E3%81%82"*500000;CGI.unescape(s)' 2.51s user 4.92s system 98% cpu 7.560 total ruby19 -r./lib/cgi/util.rb -e's="%E3%81%82"*500000;CGI.unescape(s)' 3.61s user 0.07s system 99% cpu 3.681 total ruby19 -rcgi/util -e's="abc%E3%81%82"*500000;CGI.unescape(s)' 9.17s user 0.10s system 99% cpu 9.310 total ruby19 -r./lib/cgi/util.rb -e's="abc%E3%81%82"*500000;CGI.unescape(s)' 3.84s user 0.09s system 99% cpu 3.932 total ruby19 -rcgi/util -e's="abc"*500000;CGI.unescape(s)' 0.12s user 0.03s system 98% cpu 0.156 total ruby19 -r./lib/cgi/util.rb -e's="abc"*500000;CGI.unescape(s)' 0.11s user 0.03s system 98% cpu 0.140 total -- NARUSE, Yui