Skip to content

Commit

Permalink
Address `warning: URI::RFC3986_PARSER.make_regexp is obsoleted. Use U…
Browse files Browse the repository at this point in the history
…RI::RFC2396_PARSER.make_regexp explicitly.` warning

This commit addresses `warning: URI::RFC3986_PARSER.make_regexp is obsoleted. Use URI::RFC2396_PARSER.make_regexp explicitly.` warning

Ruby 3.4 changes URI::DEFAULT_PARSER to URI::RFC3986_Parser and deprecates URI::RFC3986_PARSER.make_regexp.

This commit uses `URI::RFC2396_PARSER` only if it is available for these versions:

- `uri` v0.12.2 for Ruby 3.2/3.1
- `uri` v0.13.1 for Ruby 3.3
- Ruby 3.4.0dev

Fix teamcapybara#2778
Refer https://bugs.ruby-lang.org/issues/19266
  • Loading branch information
yahonda committed Oct 12, 2024
1 parent 0480f90 commit 1c31d62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/capybara/session/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class SessionConfig

attr_accessor(*OPTIONS)

URI_PARSER = defined?(::URI::RFC2396_PARSER) ? ::URI::RFC2396_PARSER : ::URI::DEFAULT_PARSER
private_constant :URI_PARSER

##
# @!method always_include_port
# See {Capybara.configure}
Expand Down Expand Up @@ -83,7 +86,7 @@ def server_errors=(errors)

remove_method :app_host=
def app_host=(url)
unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
unless url.nil? || url.match?(URI_PARSER.make_regexp)
raise ArgumentError, "Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
end

Expand All @@ -92,7 +95,7 @@ def app_host=(url)

remove_method :default_host=
def default_host=(url)
unless url.nil? || url.match?(URI::DEFAULT_PARSER.make_regexp)
unless url.nil? || url.match?(URI_PARSER.make_regexp)
raise ArgumentError, "Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{url.inspect}."
end

Expand Down

0 comments on commit 1c31d62

Please sign in to comment.