nitter icon indicating copy to clipboard operation
nitter copied to clipboard

Punycode support

Open shirenn opened this issue 3 years ago • 4 comments

RFC5891 provides a way to use internationalized domain names. Currently they are not rendered properly in nitter (see there for an example)

shirenn avatar Feb 15 '22 13:02 shirenn

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.

shirenn avatar Feb 15 '22 13:02 shirenn

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

makinori avatar May 19 '22 03:05 makinori

This is fixed in Nim devel, no idea when it'll make it into an actual release though. image

zedeus avatar May 19 '22 07:05 zedeus

Thought I'd leave a bump since it seems to be fixed on Nim :)

image image

derspyy avatar Oct 25 '22 00:10 derspyy