everypolitician/scraped

AbsoluteURLs decorate -- URI.unescape is obsolete

Opened this issue · 2 comments

Problem

URI.unescape has been deprecated.

/lib/scraped/response/decorator/absolute_urls.rb:21:in `absolute_url': warning: URI.unescape is obsolete

Solution

Replace URI.encode and URI.decode with CGI.escape and CGI.unescape.

It's complicated: http://stackoverflow.com/questions/2824126/whats-the-difference-between-uri-escape-and-cgi-escape

One solution is to use the addressable gem:

Addressable is a replacement for the URI implementation that is part of Ruby's standard library. It more closely conforms to RFC 3986, RFC 3987, and RFC 6570 (level 4), providing support for IRIs and URI templates.

Example:

rel_url = '/person 123'
Addressable::URI.parse(rel_url).normalize.to_s
=> "/person%20123"

Addressable handles square brackets

Addressable::URI.parse('/person[123]').normalize.to_s
=> "/person%5B123%5D"

N.b. this is an issue under Ruby 2.4.0, though I can't immediately find a changelog entry saying as much 😕

This is the issue on the Ruby bug tracker - https://bugs.ruby-lang.org/issues/4167