diff --git a/lib/active_resource.rb b/lib/active_resource.rb index 239d1d2d73..b78617d5f3 100644 --- a/lib/active_resource.rb +++ b/lib/active_resource.rb @@ -23,6 +23,8 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ +require "uri" + require "active_support" require "active_model" require "active_resource/exceptions" @@ -31,6 +33,8 @@ module ActiveResource extend ActiveSupport::Autoload + URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new + autoload :Base autoload :Callbacks autoload :Connection diff --git a/lib/active_resource/base.rb b/lib/active_resource/base.rb index 766338b26f..4dd31df9de 100644 --- a/lib/active_resource/base.rb +++ b/lib/active_resource/base.rb @@ -11,7 +11,6 @@ require "active_support/core_ext/object/to_query" require "active_support/core_ext/object/duplicable" require "set" -require "uri" require "active_resource/connection" require "active_resource/formats" @@ -490,8 +489,8 @@ def site=(site) self._site = nil else self._site = create_site_uri_from(site) - self._user = URI::DEFAULT_PARSER.unescape(_site.user) if _site.user - self._password = URI::DEFAULT_PARSER.unescape(_site.password) if _site.password + self._user = URI_PARSER.unescape(_site.user) if _site.user + self._password = URI_PARSER.unescape(_site.password) if _site.password end end @@ -750,7 +749,7 @@ def prefix_source # Default value is site.path. def prefix=(value = "/") # Replace :placeholders with '#{embedded options[:lookups]}' - prefix_call = value.gsub(/:\w+/) { |key| "\#{URI::DEFAULT_PARSER.escape options[#{key}].to_s}" } + prefix_call = value.gsub(/:\w+/) { |key| "\#{URI_PARSER.escape options[#{key}].to_s}" } # Clear prefix parameters in case they have been cached @prefix_parameters = nil diff --git a/lib/active_resource/connection.rb b/lib/active_resource/connection.rb index ca2515c421..200e23fca0 100644 --- a/lib/active_resource/connection.rb +++ b/lib/active_resource/connection.rb @@ -5,7 +5,6 @@ require "net/https" require "date" require "time" -require "uri" module ActiveResource # Class to handle connections to remote web services. @@ -43,8 +42,8 @@ def initialize(site, format = ActiveResource::Formats::JsonFormat, logger: nil) def site=(site) @site = site.is_a?(URI) ? site : URI.parse(site) @ssl_options ||= {} if @site.is_a?(URI::HTTPS) - @user = URI::DEFAULT_PARSER.unescape(@site.user) if @site.user - @password = URI::DEFAULT_PARSER.unescape(@site.password) if @site.password + @user = URI_PARSER.unescape(@site.user) if @site.user + @password = URI_PARSER.unescape(@site.password) if @site.password end # Set the proxy for remote service. @@ -173,8 +172,8 @@ def http def new_http if @proxy - user = URI::DEFAULT_PARSER.unescape(@proxy.user) if @proxy.user - password = URI::DEFAULT_PARSER.unescape(@proxy.password) if @proxy.password + user = URI_PARSER.unescape(@proxy.user) if @proxy.user + password = URI_PARSER.unescape(@proxy.password) if @proxy.password Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, user, password) else Net::HTTP.new(@site.host, @site.port)