altmetric / embiggen

A Ruby library to expand shortened URLs
https://rubygems.org/gems/embiggen
MIT License
124 stars 6 forks source link

Gracefully handle invalid Location headers #4

Closed mudge closed 9 years ago

mudge commented 9 years ago

While RFC 7231 specifies that Location headers should be valid URI references, we have seen headers with unescaped characters in them, e.g. http://shar.es/1p3DSI:

$ curl -I http://shar.es/1p3DSI                                                                                                                        HTTP/1.1 301 Moved Permanently
Location: http://paradrasi.gr/2015/04/19/ούτε-σεισμοί-ούτε-λιμοί-ούτε-καταποντ/

When passed to URI, this fails with an InvalidURIError as URIs must be ASCII-only.

mudge commented 9 years ago

A tricky issue here is that URI.escape and URI.unescape have actually been deprecated. See http://stackoverflow.com/questions/2824126/whats-the-difference-between-uri-escape-and-cgi-escape#answer-13059657 but the conclusion is to use Addressable instead for encoding URIs.

mudge commented 9 years ago

Fixed in 0.2.0.