mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #32210 from kivikakk/uri-selective-monkeypatch
Only apply URI.unescape monkey-patch if detected to be required
This commit is contained in:
commit
eec723f69a
1 changed files with 9 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue