From 82fb03731b75ba0c948fe85e8e45b7b9b0dbecd4 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:11:57 +0200 Subject: [PATCH] Avoid a deprecation warning on Ruby 3.4 with the uri gem See the added comment for a detailed explanation --- lib/tapioca/helpers/source_uri.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tapioca/helpers/source_uri.rb b/lib/tapioca/helpers/source_uri.rb index ff31567f1..e2a9726f6 100644 --- a/lib/tapioca/helpers/source_uri.rb +++ b/lib/tapioca/helpers/source_uri.rb @@ -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) + alias_method(:gem_name, :host) alias_method(:line_number, :fragment) @@ -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, } )