I'm having a textfield where the user can add an URL with I'm having a textfield where the user can add an URL with QUrl::fromUserInput()
and it then will be put into a list.
If I use special characters in the URL like "http://blöd.de/"
it will be shown as "http://blöd.de/"
but if I only type in "ö"
it will get converted to the punycode "http://xn--nda/"
.
I tried every QUrl::FormattingOptions
and every QUrl::ParsingMode
qDebug() << QUrl::fromUserInput("blöd.de"); // results in: http://blöd.de
qDebug() << QUrl::fromUserInput("ö"); // results in: http://xn--nda
Does somebody have an idea how I can convert this punycode back to the special character? And why is it only not converted when I have a top level domain?
The reason some urls are shown with Unicode characters and others with punnycode is to prevent homograph attacks.
One way to decide how to behave for a specific url is by the mean of a TLD whitelist.
In Qt you can see and edit the whitelist using QUrl::idnWhitelist()
and QUrl::setIdnWhitelist(const QStringList &list)
.
In your example .de
is in the whitelist, but .ö
is not. That is why you can see a difference in behaviour.