zedeus / nitter

Alternative Twitter front-end
https://nitter.net
GNU Affero General Public License v3.0
10.12k stars 534 forks source link

Punycode support #552

Open shirenn opened 2 years ago

shirenn commented 2 years ago

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

shirenn commented 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.

makidoll commented 2 years ago

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

zedeus commented 2 years ago

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

derspyy commented 2 years ago

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

image image