aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2018-03-08 17:23:47 -0800
committerGitHub <noreply@github.com>2018-03-08 17:23:47 -0800
commiteec723f69ad0e2e957f9c9bca350a6e032c1b58f (patch)
tree33b142dc83ea3d37c45c0ba3b74c97be7102c780
parent190744cd8ed014915803fa805996be04dc750d9d (diff)
parent8f5f2bf915f43fe7165440460830c5939af10ad8 (diff)
downloadrails-eec723f69ad0e2e957f9c9bca350a6e032c1b58f.tar.gz
rails-eec723f69ad0e2e957f9c9bca350a6e032c1b58f.tar.bz2
rails-eec723f69ad0e2e957f9c9bca350a6e032c1b58f.zip
Merge pull request #32210 from kivikakk/uri-selective-monkeypatch
Only apply URI.unescape monkey-patch if detected to be required
-rw-r--r--activesupport/lib/active_support/core_ext/uri.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/uri.rb b/activesupport/lib/active_support/core_ext/uri.rb
index c4ac0baa32..dadabb02e5 100644
--- a/activesupport/lib/active_support/core_ext/uri.rb
+++ b/activesupport/lib/active_support/core_ext/uri.rb
@@ -1,10 +1,17 @@
# frozen_string_literal: true
require "uri"
-str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
+str = "\xE6\x97\xA5"
parser = URI::Parser.new
-unless str == parser.unescape(parser.escape(str))
+needs_monkeypatch =
+ begin
+ str + str != parser.unescape(str + parser.escape(str).force_encoding(Encoding::UTF_8))
+ rescue Encoding::CompatibilityError
+ true
+ end
+
+if needs_monkeypatch
require "active_support/core_ext/module/redefine_method"
URI::Parser.class_eval do
silence_redefinition_of_method :unescape