8

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

 3 years ago
source link: https://fuzzyblog.io/blog/ruby/2020/05/12/die-uri-parse-die-long-live-the-zen-of-addressable.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

May 12, 2020

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

  • [Stack Overflow] (https://stackoverflow.com/questions/9082732/how-can-i-extract-a-url-with-non-english-characters-from-a-string)
  • Home Page

Shoutout

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


Posted In: #ruby


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK