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

Avoid a deprecation warning on Ruby 3.4 with the uri gem #2026

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
9 changes: 8 additions & 1 deletion lib/tapioca/helpers/source_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Source < URI::File
T::Array[Symbol],
)

# `uri` for Ruby 3.4 switched the default parser from RFC2396 to RFC3986. The new parser emits a deprecation
# warning on a few methods and delegates them to RFC2396, namely `extract`/`make_regexp`/`escape`/`unescape`.
# On earlier versions of the uri gem, the RFC2396_PARSER constant doesn't exist, so it needs some special
# handling to select a parser that doesn't emit deprecations. While it was backported to Ruby 3.1, users may
# have the uri gem in their own bundle and thus not use a compatible version.
PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Looks like uri v0.10.0 that defined RFC2396_PARSER was released in 2020. Do you think it'll be problematic in practice to only use RFC2396_PARSER.escape?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant has only been introduced very recently: https://github.com/ruby/uri/releases/tag/v0.13.1

Do you think it'll be problematic in practice to only use RFC2396_PARSER.escape

No. It's what is being used for ages in gems already and there is no alternative. To be honest, I have no idea why these emit a deprecation in the first place. The rack folks deem this ok: rack/rack#2242 and rack/rack#2248

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the constant is new I think it's good to hold off on using it exclusively as you mentioned in the description.


alias_method(:gem_name, :host)
alias_method(:line_number, :fragment)

Expand All @@ -40,7 +47,7 @@ def build(gem_name:, gem_version:, path:, line_number:)
{
scheme: "source",
host: gem_name,
path: DEFAULT_PARSER.escape("/#{gem_version}/#{path}"),
path: PARSER.escape("/#{gem_version}/#{path}"),
fragment: line_number,
}
)
Expand Down
Loading