Skip to content

Commit

Permalink
Merge pull request #6879 from arnaud-morvan/server_fix_url_params_dec…
Browse files Browse the repository at this point in the history
…oding

[server] Avoid %2B to be interpreted as space in querystring
  • Loading branch information
rldhont authored May 2, 2018
2 parents 73ad80f + 4087521 commit 9e5f382
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 9e5f382

Please sign in to comment.