From 5e687fbb45ad912c04ced7be1cd8f6b9e5219bbb Mon Sep 17 00:00:00 2001 From: moro Date: Sun, 15 Feb 2009 19:34:04 +0900 Subject: [PATCH] Ruby 1.9.1p0's URI.decode() bug fix backport to fix Ruby 1.9.1p0 bug on [ruby-dev:38005]. --- activesupport/lib/active_support/core_ext/uri.rb | 13 +++++++++++++ activesupport/test/core_ext/uri_ext_test.rb | 11 +++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/uri.rb create mode 100644 activesupport/test/core_ext/uri_ext_test.rb diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb new file mode 100644 index 0000000..26b050b --- /dev/null +++ b/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 + diff --git a/activesupport/test/core_ext/uri_ext_test.rb b/activesupport/test/core_ext/uri_ext_test.rb new file mode 100644 index 0000000..f25bc97 --- /dev/null +++ b/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 -- 1.6.0.1