Skip to content

Commit

Permalink
Better fix for #39243: decode in uri
Browse files Browse the repository at this point in the history
instead of handling that inside the wms routines.
  • Loading branch information
elpaso committed Oct 13, 2020
1 parent 40997ff commit c8f90c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsdatasourceuri.cpp
Expand Up @@ -638,7 +638,7 @@ void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
url.setQuery( QString::fromLatin1( uri ) );
const QUrlQuery query( url );

const auto constQueryItems = query.queryItems();
const auto constQueryItems = query.queryItems( QUrl::ComponentFormattingOption::FullyDecoded );
for ( const QPair<QString, QString> &item : constQueryItems )
{
if ( item.first == QLatin1String( "username" ) )
Expand Down
5 changes: 2 additions & 3 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -42,9 +42,8 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
uri.setEncodedUri( uriString );

// Setup authentication
QUrlQuery query{ uriString };
mAuth.mUserName = query.queryItemValue( QStringLiteral( "username" ), QUrl::ComponentFormattingOption::FullyDecoded );
mAuth.mPassword = query.queryItemValue( QStringLiteral( "password" ), QUrl::ComponentFormattingOption::FullyDecoded );
mAuth.mUserName = uri.username();
mAuth.mPassword = uri.password();

if ( !uri.authConfigId().isEmpty() )
{
Expand Down
9 changes: 9 additions & 0 deletions tests/src/core/testqgsdatasourceuri.cpp
Expand Up @@ -290,6 +290,15 @@ void TestQgsDataSourceUri::checkAuthParams()
QVERIFY( uri.param( QStringLiteral( "authcfg" ) ).isEmpty() );
QVERIFY( uri.authConfigId().isEmpty() );

// issue GH #39243
QgsDataSourceUri uri4;
uri4.setEncodedUri( QStringLiteral( "dpiMode=7&url=http://localhost:8000/ows/?MAP%3D/home/bug.qgs&username=username&password=pa%25%25word" ) );

QCOMPARE( uri4.param( QStringLiteral( "username" ) ), QStringLiteral( "username" ) );
QCOMPARE( uri4.username(), QStringLiteral( "username" ) );
QCOMPARE( uri4.param( QStringLiteral( "password" ) ), QStringLiteral( "pa%%word" ) );
QCOMPARE( uri4.password(), QStringLiteral( "pa%%word" ) );

}


Expand Down

0 comments on commit c8f90c1

Please sign in to comment.