--C7zPtVaVf+AK4Oqc
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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
where Matz say "Then don't use ugly dollar variables" 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
Thanks, I'll be waiting your response.
--
Gast齊 Ramos
--C7zPtVaVf+AK4Oqc
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="cgi_escape_work_with_blocks_and_avoid_dollar_variables.patch"
Index: lib/cgi.rb
--- lib/cgi.rb (revision 26114)
+++ lib/cgi.rb (working copy)
@@ -1,14 +1,14 @@
-#
+#
# cgi.rb - cgi support library
-#
+#
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
-#
+#
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
#
# Author: Wakou Aoyama <wakou / ruby-lang.org>
#
-# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
-#
+# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
+#
# Overview
#
# The Common Gateway Interface (CGI) is a simple protocol
@@ -18,7 +18,7 @@
# parameters of the request passed in either in the
# environment (GET) or via $stdin (POST), and everything
# it prints to $stdout is returned to the client.
-#
+#
# This file holds the +CGI+ class. This class provides
# functionality for retrieving HTTP request parameters,
# managing cookies, and generating HTML output. See the
@@ -77,18 +77,18 @@
#
#
# For each of these variables, there is a corresponding attribute with the
-# same name, except all lower case and without a preceding HTTP_.
+# same name, except all lower case and without a preceding HTTP_.
# +content_length+ and +server_port+ are integers; the rest are strings.
#
# Parameters
#
# The method #params() returns a hash of all parameters in the request as
# name/value-list pairs, where the value-list is an Array of one or more
-# values. The CGI object itself also behaves as a hash of parameter names
-# to values, but only returns a single value (as a String) for each
+# values. The CGI object itself also behaves as a hash of parameter names
+# to values, but only returns a single value (as a String) for each
# parameter name.
#
-# For instance, suppose the request contains the parameter
+# For instance, suppose the request contains the parameter
# "favourite_colours" with the multiple values "blue" and "green". The
# following behaviour would occur:
#
@@ -107,7 +107,7 @@
#
# Multipart requests
#
-# If a request's method is POST and its content type is multipart/form-data,
+# If a request's method is POST and its content type is multipart/form-data,
# then it may contain uploaded files. These are stored by the QueryExtension
# module in the parameters of the request. The parameter name is the name
# attribute of the file input field, as usual. However, the value is not
@@ -138,7 +138,7 @@
#
# Each HTML element has a corresponding method for generating that
# element as a String. The name of this method is the same as that
-# of the element, all lowercase. The attributes of the element are
+# of the element, all lowercase. The attributes of the element are
# passed in as a hash, and the body as a no-argument block that evaluates
# to a String. The HTML generation module knows which elements are
# always empty, and silently drops any passed-in body. It also knows
@@ -152,57 +152,57 @@
# as arguments, rather than via a hash.
#
# Examples of use
-#
+#
# Get form values
-#
+#
# require "cgi"
# cgi GI.new
# value gi['field_name'] # <