Skip to content

Commit

Permalink
Server OGC API: fix url path match
Browse files Browse the repository at this point in the history
Fixes #45439
  • Loading branch information
elpaso committed Oct 7, 2021
1 parent 09cfa8a commit 7cd8f09
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/server/qgsserverogcapihandler.cpp
Expand Up @@ -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() };
Expand Down
51 changes: 51 additions & 0 deletions tests/src/python/test_qgsserver_api.py
Expand Up @@ -1749,6 +1749,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):
Expand Down Expand Up @@ -2000,6 +2030,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 7cd8f09

Please sign in to comment.