aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/uri.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/uri.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/uri.rb25
1 files changed, 25 insertions, 0 deletions
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 0000000000..cdd81ae562
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/uri.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require "uri"
+
+if RUBY_VERSION < "2.6.0"
+ require "active_support/core_ext/module/redefine_method"
+ URI::Parser.class_eval do
+ silence_redefinition_of_method :unescape
+ def unescape(str, escaped = /%[a-fA-F\d]{2}/)
+ # TODO: Are we actually sure that ASCII == UTF-8?
+ # YK: My initial experiments say yes, but let's be sure please
+ enc = str.encoding
+ enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
+ str.dup.force_encoding(Encoding::ASCII_8BIT).gsub(escaped) { |match| [match[1, 2].hex].pack("C") }.force_encoding(enc)
+ end
+ end
+end
+
+module URI
+ class << self
+ def parser
+ @parser ||= URI::Parser.new
+ end
+ end
+end