Skip to content
Permalink
Browse files

Fix empty strings in proxy exclude list results in proxy being skippe…

…d for ALL hosts

Fixes #20213

(cherry picked from commit cf1cf0f)
  • Loading branch information
nyalldawson committed Feb 1, 2019
1 parent a6cad4d commit 34625110327c5bec4969c2a42cfa8c210bd3b630
Showing with 16 additions and 3 deletions.
  1. +7 −1 src/app/qgsoptions.cpp
  2. +9 −2 src/core/qgsnetworkaccessmanager.cpp
@@ -360,6 +360,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
const QStringList excludedUrlPathList = mSettings->value( QStringLiteral( "proxy/proxyExcludedUrls" ) ).toStringList();
for ( const QString &path : excludedUrlPathList )
{
if ( path.trimmed().isEmpty() )
continue;

QListWidgetItem *newItem = new QListWidgetItem( mExcludeUrlListWidget );
newItem->setText( path );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
@@ -1382,9 +1385,12 @@ void QgsOptions::saveOptions()

//url to exclude from proxys
QStringList excludedUrls;
excludedUrls.reserve( mExcludeUrlListWidget->count() );
for ( int i = 0; i < mExcludeUrlListWidget->count(); ++i )
{
excludedUrls << mExcludeUrlListWidget->item( i )->text();
const QString host = mExcludeUrlListWidget->item( i )->text();
if ( !host.trimmed().isEmpty() )
excludedUrls << host;
}
mSettings->setValue( QStringLiteral( "proxy/proxyExcludedUrls" ), excludedUrls );

@@ -74,7 +74,7 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory

Q_FOREACH ( const QString &exclude, nam->excludeList() )
{
if ( url.startsWith( exclude ) )
if ( !exclude.trimmed().isEmpty() && url.startsWith( exclude ) )
{
QgsDebugMsgLevel( QStringLiteral( "using default proxy for %1 [exclude %2]" ).arg( url, exclude ), 4 );
return QList<QNetworkProxy>() << QNetworkProxy();
@@ -164,6 +164,13 @@ void QgsNetworkAccessManager::setFallbackProxyAndExcludes( const QNetworkProxy &

mFallbackProxy = proxy;
mExcludedURLs = excludes;
// remove empty records from excludes list -- these would otherwise match ANY url, so the proxy would always be skipped!
mExcludedURLs.erase( std::remove_if( mExcludedURLs.begin(), mExcludedURLs.end(), // clazy:exclude=detaching-member
[]( const QString & url )
{
return url.trimmed().isEmpty();
} ), mExcludedURLs.end() ); // clazy:exclude=detaching-member

}

QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData )
@@ -316,7 +323,7 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache( Qt::ConnectionType conn
bool proxyEnabled = settings.value( QStringLiteral( "proxy/proxyEnabled" ), false ).toBool();
if ( proxyEnabled )
{
excludes = settings.value( QStringLiteral( "proxy/proxyExcludedUrls" ), "" ).toStringList();
excludes = settings.value( QStringLiteral( "proxy/proxyExcludedUrls" ), QStringList() ).toStringList();

//read type, host, port, user, passw from settings
QString proxyHost = settings.value( QStringLiteral( "proxy/proxyHost" ), "" ).toString();

0 comments on commit 3462511

Please sign in to comment.
You can’t perform that action at this time.