Skip to content

Commit

Permalink
Fix empty strings in proxy exclude list results in proxy being skippe…
Browse files Browse the repository at this point in the history
…d for ALL hosts

Fixes #20213

(cherry picked from commit cf1cf0f)
  • Loading branch information
nyalldawson committed Feb 1, 2019
1 parent a6cad4d commit 3462511
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );

Expand Down
11 changes: 9 additions & 2 deletions src/core/qgsnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3462511

Please sign in to comment.