trailing slash in url causes 404 error

when accessing samples for a specific meter, appending a trailing
slash will add an empty target path to 'remainder', in turn
triggering 404 error. in case last target path in remainder, we
will drop that empty instance.

Change-Id: I583a0fe9755c9bec8bcb08b13a3f1d03a3acf336
Fixes:Bug#1202739
This commit is contained in:
Gordon Chung 2013-07-19 14:51:28 -04:00
parent 0b50ac2f59
commit e757d69a3c
2 changed files with 7 additions and 0 deletions

View File

@ -618,6 +618,9 @@ class MetersController(rest.RestController):
@pecan.expose()
def _lookup(self, meter_id, *remainder):
# NOTE(gordc): drop last path if empty (Bug #1202739)
if remainder and not remainder[-1]:
remainder = remainder[:-1]
return MeterController(meter_id), remainder
@wsme_pecan.wsexpose([Meter], [Query])

View File

@ -82,6 +82,10 @@ class TestListEvents(FunctionalTest):
data = self.get_json('/meters/instance')
self.assertEquals(2, len(data))
def test_all_trailing_slash(self):
data = self.get_json('/meters/instance/')
self.assertEquals(2, len(data))
def test_all_limit(self):
data = self.get_json('/meters/instance?limit=1')
self.assertEquals(1, len(data))