Skip to content
Permalink
Browse files

Server: remove double url decoding

Fixes #41116 and #39436 (test taken from that)

(cherry picked from commit 55573ed)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 9378566 commit 7a7e56a9fa2c62612aeb9dc044fbd134cf2bcd98
Showing with 26 additions and 4 deletions.
  1. +1 −4 src/server/qgsrequesthandler.cpp
  2. +25 −0 tests/src/server/testqgsserverquerystringparameter.cpp
@@ -220,10 +220,7 @@ void QgsRequestHandler::parseInput()
const QList<pair_t> items = query.queryItems();
for ( const pair_t &pair : items )
{
// QUrl::fromPercentEncoding doesn't replace '+' with space
const QString key = QUrl::fromPercentEncoding( QString( pair.first ).replace( '+', ' ' ).toUtf8() );
const QString value = QUrl::fromPercentEncoding( QString( pair.second ).replace( '+', ' ' ).toUtf8() );
mRequest.setParameter( key.toUpper(), value );
mRequest.setParameter( pair.first, pair.second );
}
setupParameters();
}
@@ -23,6 +23,9 @@
#include "qgsserverapicontext.h"
#include "qgsserverrequest.h"
#include "qgsserverexception.h"
#include "qgsrequesthandler.h"
#include "qgsbufferserverrequest.h"
#include "qgsbufferserverresponse.h"

/**
* \ingroup UnitTests
@@ -56,6 +59,9 @@ class TestQgsServerQueryStringParameter : public QObject

// Test default values
void testDefaultValues();

// Test QgsRequestHandler::parseInput (i.e. POST requests) with special chars
void testParseInput();
};


@@ -174,5 +180,24 @@ void TestQgsServerQueryStringParameter::testDefaultValues()

}

void TestQgsServerQueryStringParameter::testParseInput()
{
// Request with layers "a", "b", "c" and "äös + %&#"
QByteArray data( "SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=a%2Cb%2Cc%2C%C3%A4%C3%B6s+%2B+%25%26%23" );
QgsBufferServerRequest request( QStringLiteral( "http://localhost/wms/test" ), QgsServerRequest::PostMethod, QgsServerRequest::Headers(), &data );
QgsBufferServerResponse response;

QgsRequestHandler requestHandler( request, response );
requestHandler.parseInput();

QgsServerParameters params = request.serverParameters();
QMap<QString, QString> paramsMap = params.toMap();
QCOMPARE( paramsMap["SERVICE"], QStringLiteral( "WMS" ) );
QCOMPARE( paramsMap["VERSION"], QStringLiteral( "1.3.0" ) );
QCOMPARE( paramsMap["REQUEST"], QStringLiteral( "GetMap" ) );
QCOMPARE( paramsMap["LAYERS"], QStringLiteral( "a,b,c,äös + %&#" ) );
}


QGSTEST_MAIN( TestQgsServerQueryStringParameter )
#include "testqgsserverquerystringparameter.moc"

0 comments on commit 7a7e56a

Please sign in to comment.