From 8ad68d96dfeb5ed7c5f576fcc3824118e9977aa0 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Fri, 22 Mar 2024 01:00:08 -0400 Subject: [PATCH] fix: url handler and encoded ACE / Punycode / percent encoded URLs --- src/main.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.cc b/src/main.cc index 27eb2952..8d573e69 100644 --- a/src/main.cc +++ b/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 } }