Skip to content
Permalink
Browse files
Server OGC API: fix url path match
Fixes #45439
  • Loading branch information
elpaso authored and nyalldawson committed Nov 1, 2021
1 parent a51e720 commit 77b3433e105a34e455540dd64e82f90c9db2e816
Showing with 53 additions and 1 deletion.
  1. +2 −1 src/server/qgsserverogcapihandler.cpp
  2. +51 −0 tests/src/python/test_qgsserver_api.py
@@ -46,7 +46,8 @@ QVariantMap QgsServerOgcApiHandler::values( const QgsServerApiContext &context )
// value() calls the validators and throws an exception if validation fails
result[p.name()] = p.value( context );
}
const auto match { path().match( context.request()->url().toString() ) };
const auto sanitizedPath { QgsServerOgcApi::sanitizeUrl( context.request()->url() ).path() };
const auto match { path().match( sanitizedPath ) };
if ( match.hasMatch() )
{
const auto constNamed { path().namedCaptureGroups() };
@@ -1747,6 +1747,36 @@ def templatePath(self, context):
return self.templatePathOverride


class Handler4(QgsServerOgcApiHandler):

def path(self):
return QtCore.QRegularExpression("/tms/(?P<tilemapid>[^/]+)")

def operationId(self):
return "handler4"

def summary(self):
return "Fourth of its name"

def description(self):
return "The fourth handler ever"

def linkTitle(self):
return "Handler Four Link Title"

def linkType(self):
return QgsServerOgcApi.data

def handleRequest(self, context):
"""Simple mirror: returns the parameters"""

self.params = self.values(context)
self.write(self.params, context)

def parameters(self, context):
return []


class HandlerException(QgsServerOgcApiHandler):

def __init__(self):
@@ -1998,6 +2028,27 @@ def testOgcApiHandlerException(self):

del(project)

def test_path_capture(self):
"""Test issue GH #45439"""
project = QgsProject()

api = QgsServerOgcApi(self.server.serverInterface(),
'/', 'apifour', 'a fourth api', '1.2')

h4 = Handler4()
api.registerHandler(h4)

request = QgsBufferServerRequest(
'http://localhost:19876/tms/france_parts.json?MAP=france_parts')
response = QgsBufferServerResponse()

ctx = QgsServerApiContext(
'/services/api4', request, response, project, self.server.serverInterface())

api.executeRequest(ctx)

self.assertEqual(h4.params, {'tilemapid': 'france_parts.json'})


if __name__ == '__main__':
unittest.main()

0 comments on commit 77b3433

Please sign in to comment.