Skip to content

Commit

Permalink
Fix parameter name decoding when using POST + urlencoded
Browse files Browse the repository at this point in the history
This is a followup of dfe48d1 which solved
the issue for parameter values.

Fixes #17694
  • Loading branch information
peppsac committed Dec 15, 2017
1 parent e9feeaa commit adb7af9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/server/qgsrequesthandler.cpp
Expand Up @@ -228,10 +228,12 @@ void QgsRequestHandler::parseInput()
typedef QPair<QString, QString> pair_t;
QUrlQuery query( inputString );
QList<pair_t> items = query.queryItems();
Q_FOREACH ( const pair_t &pair, items )
Q_FOREACH ( pair_t pair, items )
{
const QString value = QUrl::fromPercentEncoding( pair.second.toUtf8() );
mRequest.setParameter( pair.first.toUpper(), value );
// QUrl::fromPercentEncoding doesn't replace '+' with space
const QString key = QUrl::fromPercentEncoding( pair.first.replace( '+', ' ' ).toUtf8() );
const QString value = QUrl::fromPercentEncoding( pair.second.replace( '+', ' ' ).toUtf8() );
mRequest.setParameter( key.toUpper(), value );
}
setupParameters();
}
Expand Down
10 changes: 6 additions & 4 deletions tests/src/python/test_qgsserver_wms_getprint.py
Expand Up @@ -33,6 +33,7 @@

from test_qgsserver import QgsServerTestBase
from qgis.core import QgsProject
from qgis.server import QgsServerRequest

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = b'MAP=[^"]+|Content-Length: \d+'
Expand Down Expand Up @@ -302,7 +303,7 @@ def test_wms_getprint_opacity(self):
"REQUEST": "GetPrint",
"TEMPLATE": "layoutA4",
"FORMAT": "png",
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0%3AEXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0:LAYERS": "Country,Hello",
"CRS": "EPSG:3857",
"SELECTION": "Country: 4",
Expand All @@ -313,22 +314,23 @@ def test_wms_getprint_opacity(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetPrint_Opacity")

qs = "?" + "&".join(["%s=%s" % i for i in list({
def test_wms_getprint_opacity_post(self):
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetPrint",
"TEMPLATE": "layoutA4",
"FORMAT": "png",
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0%3AEXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0:LAYERS": "Country,Hello",
"CRS": "EPSG:3857",
"SELECTION": "Country: 4",
"LAYERS": "Country,Hello",
"OPACITIES": "125%2C125"
}.items())])

r, h = self._result(self._execute_request(qs))
r, h = self._result(self._execute_request('', QgsServerRequest.PostMethod, data=qs.encode('utf-8')))
self._img_diff_error(r, h, "WMS_GetPrint_Opacity")

def test_wms_getprint_highlight(self):
Expand Down

0 comments on commit adb7af9

Please sign in to comment.