--000e0cd1132acaa3ef047ae341f1 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Dec 17, 2009 at 12:28 AM, Gaston Ramos <ramos.gaston / gmail.com>wrote: > Hi Ruby-Core, I attach a path that solve this problem: > > class String > alias :old_gsub :gsub > def gsub(*args, &block) > old_gsub(*args, &block) > end > end > > require 'cgi' > CGI.escape("An Interview with Criteri…") > > NoMethodError: undefined method `size' for nil:NilClass > from /usr/lib/ruby/1.8/cgi.rb:343:in `escape' > from (irb):4:in `old_gsub' > from (irb):4:in `gsub' > from /usr/lib/ruby/1.8/cgi.rb:342:in `escape' > from (irb):9 > > As you can see CGI.escape won't work well when we use gsub and blocks, this > issue was discussed in this thread: > > > http://www.justskins.com/forums/bug-when-rerouting-string-gsub-with-a-block-using-1-a-52852.html Even if you patch cgi.rb, you can use only matched string ($&) which is passed as block parameter. There are $~ (Regexp.last_match), $` (pre_match), $' (post_match) and $1, $2, $3 and so on. So your patch is fortunately adopted to cgi.rb, but not universal. So I'm against such a sectional patch. > where Matz say "Then don't use ugly dollar variables" When Matz say so? That statement doesn't face up to real situation, described above. dollar variables may be ugly but required. > so, dollar variables are > problematic in this case, I changed the dollar variables by a block > argument > variable and the problem was solved, I added 2 tests for CGI.escape and > CGI.unescape that reproduce this "problem", If you agree with this patch I > could > do other new patch in order to avoid all dollar variables inside CGI lib. > > And there is a bug in ActiveSupport realted with this issue: > > https://rails.lighthouseapp.com/projects/8994/tickets/3475-activesupportmultibytecharsgsub-fails-while-stringgsub-works > So current answer is "Don't change String#gsub when you controll all things". See also this ticket (but this is in Japanese...) http://redmine.ruby-lang.org/issues/show/546 -- NARUSE, Yui naruse / airemix.jp --000e0cd1132acaa3ef047ae341f1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div class="gmail_quote">On Thu, Dec 17, 2009 at 12:28 AM, Gaston Ramos <span dir="ltr"><ramos.gaston / gmail.com></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> Hi Ruby-Core, I attach a path that solve this problem:<br> <br> class String<br> ¨Âìéáó ºïìäßçóõºçóõâ¼âò ¨Âåæ çóõ⨪áòçó¦áíð»âìïã멼âò old_gsub(*args, &block)<br> ¨Âîä¼âò¾ end<br> <br> require 'cgi'<br> CGI.escape("An Interview with Criteri&#8230;")<br> <br> NoMethodError: undefined method `size' for nil:NilClass<br> ¨Âòï¯õóò¯ìéâ¯òõâù¯±®¸¯ãçé®ò⺳´³ºéàåóãáð妣³¹»¼âò¾ ¨Âòï¨éò⩺´ºéî àïìäßçóõ⦣³¹»¼âò¾ ¨Âòï¨éò⩺´ºéî àçóõ⦣³¹»¼âò¾ ¨Âòï¯õóò¯ìéâ¯òõâù¯±®¸¯ãçé®ò⺳´²ºéàåóãáð妣³¹»¼âò¾ from (irb):9<br> <br> As you can see CGI.escape won't work well when we use gsub and blocks, this<br> issue was discussed in this thread:<br> <br> <a href="http://www.justskins.com/forums/bug-when-rerouting-string-gsub-with-a-block-using-1-a-52852.html" target="_blank">http://www.justskins.com/forums/bug-when-rerouting-string-gsub-with-a-block-using-1-a-52852.html</a></blockquote> <div><br></div><div><div>Even if you patch cgi.rb, you can use only matchedtring ($&) which is passed as block parameter.</div><div>There are $~Regexp.last_match), $` (pre_match), $' (post_match) and $1, $2, $3 and so on.</div> <div>So your patch is fortunately adopted to cgi.rb, but not universal.</div><div><br></div><div>So I'm against such a sectional patch.</div></div><div>/div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> where Matz say "Then don't use ugly dollar variables"</blockquote><div><br></div><div>When Matz say so?</div><div>That statement doesn't face up to real situation, described above.</div><div>dollar variablesay be ugly but required.</div> <div>/div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">so, dollar variables are<br> problematic in this case, I changed the dollar variables by a block argument<br> variable and the problem was solved, I added 2 tests for CGI.escape and<br> CGI.unescape that reproduce this "problem", If you agree with this patch I could<br> do other new patch in order to avoid all dollar variables inside CGI lib.<br> <br> And there is a bug in ActiveSupport realted with this issue:<br> <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3475-activesupportmultibytecharsgsub-fails-while-stringgsub-works" target="_blank">https://rails.lighthouseapp.com/projects/8994/tickets/3475-activesupportmultibytecharsgsub-fails-while-stringgsub-works</a><br> </blockquote></div><div><br></div>So current answer is "Don't change String#gsub when you controll all things".<div><br></div><div>See also this ticket (but this is in Japanese...)</div><div>http://redmine.ruby-lang.org/issues/show/546<br clear="all"> <br>-- <br>NARUSE, Yui<br>naruse / airemix.jp<br> </div> --000e0cd1132acaa3ef047ae341f1--