Last active
December 20, 2015 10:30
-
-
Save levinalex/6115764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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