Skip to content

Commit

Permalink
Only apply monkey-patch if detected to be required
Browse files Browse the repository at this point in the history
We test the failing case we're trying to patch; only if it throws an
Exception do we patch.

Currently this will *always* throw, but upstream Ruby has patched this
bug: https://git.io/vAxKB

Signed-off-by: Ashe Connor <ashe@kivikakk.ee>
  • Loading branch information
kivikakk committed Mar 9, 2018
1 parent 6a54932 commit 8f5f2bf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions 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
Expand Down

0 comments on commit 8f5f2bf

Please sign in to comment.