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

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Sep 25, 2024

Motivation

Avoid a deprecation warning on ruby 3.4 with the uri gem.

/home/user/code/tapioca/lib/tapioca/helpers/source_uri.rb:50: warning: URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.

Implementation

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.

Additional info:

Tests

Not needed. You can verify this yourself by doing the following:

  • Add gem "uri", github: "ruby/uri" to the gemfile
  • Run RUBYOPT="-w" bundle exec rake test TEST=spec/tapioca/gem/pipeline_spec.rb TESTOPTS="--name=/location/"

See the added comment for a detailed explanation
@Earlopain Earlopain requested a review from a team as a code owner September 25, 2024 08:17
Earlopain added a commit to Earlopain/ruby-lsp that referenced this pull request Sep 25, 2024
I openend a PR to tapioca, which needs the same change: Shopify/tapioca#2026
@egiurleo egiurleo added the chore label Sep 25, 2024
# 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.

# 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.

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

@KaanOzkan KaanOzkan merged commit defb823 into Shopify:main Sep 30, 2024
17 of 18 checks passed
@Earlopain Earlopain deleted the uri-3.4 branch September 30, 2024 19:47
Earlopain added a commit to Earlopain/ruby-lsp that referenced this pull request Oct 1, 2024
I openend a PR to tapioca, which needs the same change: Shopify/tapioca#2026
vinistock pushed a commit to Shopify/ruby-lsp that referenced this pull request Oct 1, 2024
I openend a PR to tapioca, which needs the same change: Shopify/tapioca#2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants