mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
fix: url handler and encoded ACE / Punycode / percent encoded URLs
This commit is contained in:
parent
be22cb22b6
commit
8ad68d96df
18
src/main.cc
18
src/main.cc
|
@ -301,6 +301,24 @@ void processCommandLine( QCoreApplication * app, GDOptions * result )
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue