rubyists-
can any light be shed on why
CGI.escape ‘foo bar’ >> “foo+bar”
instead of
CGI.escape ‘foo bar’ >> “foo%20bar”
the ‘+’ does not work under certain browser/apache conditions it seems.
-a
···
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
‘+’ is an allowed replacement for spaces. Read both cgi.rb and
cgi-lib.rb’s escape functions. If only I know which RFC this is
contained in…
···
ahoward (ahoward@fsl.noaa.gov) wrote:
rubyists-
can any light be shed on why
CGI.escape ‘foo bar’ >> “foo+bar”
instead of
CGI.escape ‘foo bar’ >> “foo%20bar”
the ‘+’ does not work under certain browser/apache conditions it seems.
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
Judging by other responses, this is really a problem with your HTTP server.
However, there is no reason we can’t be accomodating. We do have the source
code to cgi.rb available to us and this function is easily altered to do
what you want.
Here is the raw function from my /usr/local/lib/ruby/1.7/cgi.rb file:
def CGI::escape(string)
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
‘%’ + $1.unpack(‘H2’ * $1.size).join(‘%’).upcase
end.tr(’ ', ‘+’)
end
Here is the change you need to make:
def CGI::escape(string)
string.gsub(/([^a-zA-Z0-9_.-]+)/n) do #delete the space
‘%’ + $1.unpack(‘H2’ * $1.size).join(‘%’).upcase
end #remove the tr method, which is no longer needed
end
If you don’t have access to the cgi.rb file itself (or don’t want to fiddle
with the included libraries), you can always redefine this function in
your own script by simply using it like so:
class CGI
def CGI::escape(string)
… the new definition
end
end
Just do it after you require ‘cgi’ and your new method will replace the
stock version.
-michael
···
On Thursday 05 December 2002 16:56, ahoward wrote:
rubyists-
can any light be shed on why
CGI.escape ‘foo bar’ >> “foo+bar”
instead of
CGI.escape ‘foo bar’ >> “foo%20bar”
the ‘+’ does not work under certain browser/apache conditions it seems.
RFC1866 (dated Nov 1995), Section 8.2.1:
-snip-
The form field names and values are escaped: space
characters are replaced by +', and then reserved characters are escaped as per [URL]; that is, non-alphanumeric characters are replaced by %HH’, a percent sign and two
hexadecimal digits representing the ASCII code of the
character. Line breaks, as in multi-line text field values,
are represented as CR LF pairs, i.e. `%0D%0A’.
-snip-
Reference: Parsing Example
···
On Friday 06 December 2002 03:20 am, Eric Hodel wrote:
‘+’ is an allowed replacement for spaces. Read both cgi.rb and
cgi-lib.rb’s escape functions. If only I know which RFC this is
contained in…
–
Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com
‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams
RFC1866 is for HTML 2.0; it has been obsoleted in 2000 by RFC2854,
which removes HTML from IETF to W3C control.
At the moment, I don’t have time to look at the W3C HTML definition
to see if this (+ == space replacement) is still the case.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.06 at 07.46.23
···
On Fri, 6 Dec 2002 18:45:44 +0900, Bruce Williams wrote:
On Friday 06 December 2002 03:20 am, Eric Hodel wrote:
‘+’ is an allowed replacement for spaces. Read both cgi.rb and
cgi-lib.rb’s escape functions. If only I know which RFC this is
contained in…
RFC1866 (dated Nov 1995), Section 8.2.1:
as far as i can tell, the appropriate rfc regarding uri syntax is actually
rfc2396
http://www.ietf.org/rfc/rfc2396.txt
and i am coding a replacement for CGI.escape based on that rfc unless someone
knows of a more recent doc.
also, someone reccomended
URI.escape
but i’m not sure which package it’s from. i think what was meant was
http://arika.org/ruby/uri.xhtml
but am also unsure. any info appreciated.
-a
···
On Fri, 6 Dec 2002, Austin Ziegler wrote:
RFC1866 is for HTML 2.0; it has been obsoleted in 2000 by RFC2854,
which removes HTML from IETF to W3C control.
At the moment, I don’t have time to look at the W3C HTML definition
to see if this (+ == space replacement) is still the case.
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
To be pedantic, HTML 4.01 Specification (W3C Recommendation 24 December 1999),
Section 17.13.4 does maintain the ‘+’ space encoding (referring to RFC 1738
as a reference).
···
On Friday 06 December 2002 08:08 am, Austin Ziegler wrote:
RFC1866 is for HTML 2.0; it has been obsoleted in 2000 by RFC2854,
which removes HTML from IETF to W3C control.
At the moment, I don’t have time to look at the W3C HTML definition
to see if this (+ == space replacement) is still the case.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.06 at 07.46.23
–
Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com
‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams
but 2396 obsoletes 1738 and 1808
the reality is that several of our apaches do not support the ‘+’. this is
more convincing than any rfc to me.
-a
···
On Sat, 7 Dec 2002, Bruce Williams wrote:
To be pedantic, HTML 4.01 Specification (W3C Recommendation 24 December 1999),
Section 17.13.4 does maintain the ‘+’ space encoding (referring to RFC 1738
as a reference).
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
That’s fine. I didn’t say it wasn’t historical; I mentioned the pedantic
nature of the data, in any case 
···
On Friday 06 December 2002 12:20 pm, ahoward wrote:
On Sat, 7 Dec 2002, Bruce Williams wrote:
To be pedantic, HTML 4.01 Specification (W3C Recommendation 24 December
1999), B> Section 17.13.4 does maintain the ‘+’ space encoding (referring
to RFC 1738 B> as a reference).
but 2396 obsoletes 1738 and 1808
the reality is that several of our apaches do not support the ‘+’. this is
more convincing than any rfc to me.
-a
–
Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com
‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams
for those intersted, the URI package written by akira yamada available on the
RAA is extremely complete and handles ‘+’ vs ‘%20’ in the rfc2396 fashion.
in fact, a copy of rfc2396.txt is included in the dist. the URI package
handles ftp, http, ldap, mailto, etc. there are no docs, but the test
directory should get anyone going in a hurry.
http://arika.org/ruby/uri.xhtml
(pretty cool url eh?)
this solves all the problems i was having and i would reccomend it over the
standard CGI.escape routines.
-a
···
On Sat, 7 Dec 2002, Bruce Williams wrote:
On Friday 06 December 2002 12:20 pm, ahoward wrote:
On Sat, 7 Dec 2002, Bruce Williams wrote:
To be pedantic, HTML 4.01 Specification (W3C Recommendation 24 December
1999), B> Section 17.13.4 does maintain the ‘+’ space encoding (referring
to RFC 1738 B> as a reference).
but 2396 obsoletes 1738 and 1808
the reality is that several of our apaches do not support the ‘+’. this is
more convincing than any rfc to me.
-a
That’s fine. I didn’t say it wasn’t historical; I mentioned the pedantic
nature of the data, in any case 
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================