Scott's Recipes Logo

Die URI.parse Die; Long Live the Zen of Addressable

IMG_2628.jpeg

URI.parse is a Ruby call I’ve written a thousand plus times. The unfortunate reality of URI.parse is that it doesn’t work when there are UTF-8 characters in the url. The work around is the addressable gem. So:

Gemfile

gem "addressable"

Example Usage

require 'addressable/uri'
url = 'http://www.example.com/wp content/uploads/2012/01/München.jpg'
parts = Addressable::URI.parse(url)

Sources

Shoutout

I can’t even think about URL parsing in Ruby / Elixir / JavaScript without mentioning Gamache’s FuzzyUrl library. Highly, highly recommenderd.