Skip to content
Browse files

Ruby 1.9.1p0's URI.decode() bug fix

backport to fix Ruby 1.9.1p0 bug on [ruby-dev:38005].

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 3d15e1a commit a8f32e1c86d73623cf93cdcf1683a23e3af47ce3 @moro moro committed with jeremy Feb 15, 2009
Showing with 24 additions and 0 deletions.
  1. +13 −0 activesupport/lib/active_support/core_ext/uri.rb
  2. +11 −0 activesupport/test/core_ext/uri_ext_test.rb
View
13 activesupport/lib/active_support/core_ext/uri.rb
@@ -0,0 +1,13 @@
+require 'uri'
+
+module ActiveSupport
+ if RUBY_VERSION == "1.9.1" && defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL == 0
+ ::URI::Parser.class_eval do
+ def unescape(str, escaped = @regexp[:ESCAPED])
+ enc = (str.encoding == Encoding::US_ASCII) ? Encoding::UTF_8 : str.encoding
+ str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
+ end
+ end
+ end
+end
+
View
11 activesupport/test/core_ext/uri_ext_test.rb
@@ -0,0 +1,11 @@
+require 'abstract_unit'
+
+class URITest < Test::Unit::TestCase
+ def test_uri_decode_handle_multibyte
+ str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
+ str.force_encoding(Encoding::UTF_8) if(defined? Encoding::UTF_8)
+
+ assert_equal str, ::URI.unescape( ::URI.escape(str) )
+ assert_equal str, ::URI.decode( ::URI.escape(str) )
+ end
+end

0 comments on commit a8f32e1

Please sign in to comment.
Something went wrong with that request. Please try again.