Browse Source

Applied currently available fix for ruby 'open-uri' bug described in pull request #1675. Using 'open' with a temp file causes an exception.

This is caused by the newly introduced Exchange integration dependencies 'viewpoint' and 'autodiscover' which depend on 'httpclient' which requires 'open-uri' somewhere. These cause the integration tests to fail - namely UserAgentTest#test_check_request.

Link: https://github.com/ruby/ruby/pull/1675
Thorsten Eckel 7 years ago
parent
commit
4a24bb8507
1 changed files with 20 additions and 0 deletions
  1. 20 0
      lib/core_ext/open-uri.rb

+ 20 - 0
lib/core_ext/open-uri.rb

@@ -0,0 +1,20 @@
+# rubocop:disable Style/FileName
+if Kernel.respond_to?(:open_uri_original_open)
+  module Kernel
+    private
+
+    # see: https://github.com/ruby/ruby/pull/1675
+    def open(name, *rest, &block) # :doc:
+      if name.respond_to?(:open) && !name.method(:open).parameters.empty?
+        name.open(*rest, &block)
+      elsif name.respond_to?(:to_str) &&
+            %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
+            (uri = URI.parse(name)).respond_to?(:open)
+        uri.open(*rest, &block)
+      else
+        open_uri_original_open(name, *rest, &block)
+      end
+    end
+    module_function :open
+  end
+end