Skip to content

Commit

Permalink
[server] Avoid %2B to be interpreted as space in querystring
Browse files Browse the repository at this point in the history
If '+' is replaced by ' ' after percent decoding, '%2B' is interpreted as ' '.

Fix this by replacing '+' by '%20' before percent decoding.
  • Loading branch information
arnaud-morvan committed Apr 27, 2018
1 parent de8f264 commit 4087521
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/server/qgsserverrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ QMap<QString, QString> QgsServerRequest::parameters() const
typedef QPair<QString, QString> pair_t;

QUrlQuery query( mUrl );
query.setQuery( query.query().replace( '+', QStringLiteral( "%20" ) ) );

QList<pair_t> items = query.queryItems( QUrl::FullyDecoded );
Q_FOREACH ( const pair_t &pair, items )
{
// prepare the value
QString value = pair.second;
value.replace( '+', ' ' );

mParams.insert( pair.first.toUpper(), value );
mParams.insert( pair.first.toUpper(), pair.second );
}
mDecoded = true;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsserver_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def test_requestParameters(self):
for k, v in request.headers().items():
self.assertEqual(parameters[k], v)

def test_requestParametersDecoding(self):
"""Test request parameters decoding"""
request = QgsServerRequest('http://somesite.com/somepath?parm1=val1%20%2B+val2', QgsServerRequest.GetMethod)
self.assertEqual(request.parameters()['PARM1'], 'val1 + val2')

def test_requestUrl(self):
"""Test url"""
request = QgsServerRequest('http://somesite.com/somepath', QgsServerRequest.GetMethod)
Expand Down

0 comments on commit 4087521

Please sign in to comment.