Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #210 from spastorino/master

[Regression] Rack::Utils.escape only accept strings in Ruby 1.8.7 + $KCODE = 'U'
  • Loading branch information...
commit 56c2eddcb22467e6ce9667ed820e19566cbf9987 2 parents e30452c + 48d302c
@raggi raggi authored
View
6 lib/rack/backports/uri/common.rb
@@ -10,7 +10,7 @@ module URI
TBLENCWWWCOMP_ = {} # :nodoc:
TBLDECWWWCOMP_ = {} # :nodoc:
- # Encode given +str+ to URL-encoded form data.
+ # Encode given +s+ to URL-encoded form data.
#
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
# (ASCII space) to + and converts others to %XX.
@@ -19,7 +19,8 @@ module URI
# http://www.w3.org/TR/html5/forms.html#url-encoded-form-data
#
# See URI.decode_www_form_component, URI.encode_www_form
- def self.encode_www_form_component(str)
+ def self.encode_www_form_component(s)
+ str = s.to_s
if RUBY_VERSION < "1.9" && $KCODE =~ /u/i
str.gsub(/([^ a-zA-Z0-9_.-]+)/) do
'%' + $1.unpack('H2' * Rack::Utils.bytesize($1)).join('%').upcase
@@ -37,7 +38,6 @@ def self.encode_www_form_component(str)
rescue
end
end
- str = str.to_s
str.gsub(/[^*\-.0-9A-Z_a-z]/) {|m| TBLENCWWWCOMP_[m]}
end
end
View
2  lib/rack/utils.rb
@@ -18,7 +18,7 @@ module Rack
# applications adopted from all kinds of Ruby libraries.
module Utils
- # URI escapes a string. (CGI style space to +)
+ # URI escapes. (CGI style space to +)
def escape(s)
URI.encode_www_form_component(s)
end
View
8 test/spec_utils.rb
@@ -41,6 +41,14 @@
end
end
+ should "escape objects that responds to to_s" do
+ default_kcode, $KCODE = $KCODE, 'U'
+
+ Rack::Utils.escape(:id).should.equal "id"
+
+ $KCODE = default_kcode
+ end
+
if "".respond_to?(:encode)
should "escape non-UTF8 strings" do
Rack::Utils.escape("ø".encode("ISO-8859-1")).should.equal "%F8"
Please sign in to comment.
Something went wrong with that request. Please try again.