Skip to content

@levinalex /addressable_unicode.rb
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# encoding: utf-8
require 'addressable/uri'
str = "http://उदाहरण.परीक्षा/मुख्य_पृष्ठ"
puts "original:"
puts "#=> #{str}"
#=> http://उदाहरण.परीक्षा/मुख्य_पृष्ठ
normalized = Addressable::URI.parse(str).normalize
puts "normalized:"
puts "#=> #{normalized.to_s}"
#=> http://xn--p1b6ci4b4b3a.xn--11b5bs3a9aj6g/%E0%A4%AE%E0%A5%81%E0%A4%96%E0%A5%8D%E0%A4%AF_%E0%A4%AA%E0%A5%83%E0%A4%B7%E0%A5%8D%E0%A4%A0
nicer = normalized.display_uri.to_s
puts "display_uri:"
puts "#=> #{nicer}"
#=> http://उदाहरण.परीक्षा/%E0%A4%AE%E0%A5%81%E0%A4%96%E0%A5%8D%E0%A4%AF_%E0%A4%AA%E0%A5%83%E0%A4%B7%E0%A5%8D%E0%A4%A0
display_s = Addressable::URI.parse(str).display_uri.to_s
pretty = Addressable::URI.unencode(display_s.force_encoding("ASCII-8BIT"))
puts "unencoded:"
puts "#=> #{pretty}"
#=> http://उदाहरण.परीक्षा/मुख्य_पृष्ठ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.