Be aware of the [IDNA hell](http://annevankesteren.nl/2012/11/idna-hell). The Web Hypertext Application Technology Working Group recommends following: http://url.spec.whatwg.org/#idna

Or copy it from the Perl implementation: http://search.cpan.org/~cfaerber/