lib/tapioca/helpers/source_uri.rb in tapioca-0.16.2 vs lib/tapioca/helpers/source_uri.rb in tapioca-0.16.3

- old
+ new

@@ -16,10 +16,17 @@ :line_number, ].freeze, 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) sig { returns(T.nilable(String)) } attr_reader :gem_version @@ -38,10 +45,10 @@ def build(gem_name:, gem_version:, path:, line_number:) super( { scheme: "source", host: gem_name, - path: DEFAULT_PARSER.escape("/#{gem_version}/#{path}"), + path: PARSER.escape("/#{gem_version}/#{path}"), fragment: line_number, } ) end end