Open shirenn opened 2 years ago
import std/strutils
from std/sugar import collect
from std/punycode import decode
import std/uri
echo "URI to sanitize : "
var name: string = readline(stdin)
var url: Uri = parseUri(name)
var bits: seq[string] = url.hostname.split(".")
let cleaned_bits: seq[string] = sugar.collect(newSeq):
for bit in bits:
if bit.startsWith("xn--"):
decode(bit[4 .. ^1])
else:
bit
var cleaned_hostname: string = cleaned_bits.join(".")
var cleaned_url: Uri = url
cleaned_url.hostname = cleaned_hostname
echo $cleaned_url
This snippet transforms punycode encoded uris to their utf8 representation. Though, I don't think it is really idiomatic and I wouldn't know how to insert it in nitter source.
I'm looking into maybe sending a pr with punycode support, but it seems that nim's std/punycode is broken. Even outside their playground I can't figure much out. I'll keep looking for solutions and come back later
This is fixed in Nim devel, no idea when it'll make it into an actual release though.
Thought I'd leave a bump since it seems to be fixed on Nim :)
RFC5891 provides a way to use internationalized domain names. Currently they are not rendered properly in nitter (see there for an example)