Merge pull request #1434 from shenlebantongying/fix/punycode-ace-url-handler

fix: url handler and encoded ACE / Punycode / percent encoded URLs
This commit is contained in:
xiaoyifang 2024-03-22 16:57:37 +08:00 committed by GitHub
commit e0d09302d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -301,6 +301,24 @@ void processCommandLine( QCoreApplication * app, GDOptions * result )
result->word.chop( 1 ); result->word.chop( 1 );
} }
} }
// Handle cases where we get encoded URL
if ( result->word.startsWith( QStringLiteral( "xn--" ) ) ) {
// For `kde-open` or `gio` or others, URL are encoded into ACE or Punycode
#if QT_VERSION >= QT_VERSION_CHECK( 6, 3, 0 )
result->word = QUrl::fromAce( result->word.toLatin1(), QUrl::IgnoreIDNWhitelist );
#else
// Old Qt's fromAce only applies to whitelisted domains, so we add .com to bypass this restriction :)
// https://bugreports.qt.io/browse/QTBUG-29080
result->word.append( QStringLiteral( ".com" ) );
result->word = QUrl::fromAce( result->word.toLatin1() );
result->word.chop( 4 );
#endif
}
else if ( result->word.startsWith( QStringLiteral( "%" ) ) ) {
// For Firefox or other browsers where URL are percent encoded
result->word = QUrl::fromPercentEncoding( result->word.toLatin1() );
}
#endif #endif
} }
} }