Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URI deprecation warnings #404

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/active_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -750,7 +749,7 @@ def prefix_source
# Default value is <tt>site.path</tt>.
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
Expand Down
9 changes: 4 additions & 5 deletions lib/active_resource/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require "net/https"
require "date"
require "time"
require "uri"

module ActiveResource
# Class to handle connections to remote web services.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Loading