# HG changeset patch # User Thierry Florac # Date 1550835037 -3600 # Node ID 1482a4b86075dc9c68eade683327ebab5c8fe22c # Parent 5f8deef8e5d20f958caf2f9606da6dee644b9c83 Handle empty URL when using "+" traverser diff -r 5f8deef8e5d2 -r 1482a4b86075 src/pyams_utils/traversing.py --- a/src/pyams_utils/traversing.py Mon Feb 18 17:12:39 2019 +0100 +++ b/src/pyams_utils/traversing.py Fri Feb 22 12:30:37 2019 +0100 @@ -115,17 +115,23 @@ traverser = registry.queryMultiAdapter((ob, request), ITraversable, '+') if traverser is None: raise NotFound() - ob = traverser.traverse(vpath_tuple[vroot_idx + i + 2], vpath_tuple[vroot_idx + i + 3:]) - i += 1 - return { - 'context': ob, - 'view_name': ''.join(vpath_tuple[vroot_idx + i + 2:]), - 'subpath': vpath_tuple[i + 2:], - 'traversed': vpath_tuple[:vroot_idx + i + 2], - 'virtual_root': vroot, - 'virtual_root_path': vroot_tuple, - 'root': root - } + try: + ob = traverser.traverse(vpath_tuple[vroot_idx + i + 2], vpath_tuple[vroot_idx + i + 3:]) + except IndexError: + # the "+" namespace traverser is waiting for additional elements from input URL + # so a "+" URL not followed by something else is just an error! + raise NotFound() + else: + i += 1 + return { + 'context': ob, + 'view_name': ''.join(vpath_tuple[vroot_idx + i + 2:]), + 'subpath': vpath_tuple[i + 2:], + 'traversed': vpath_tuple[:vroot_idx + i + 2], + 'virtual_root': vroot, + 'virtual_root_path': vroot_tuple, + 'root': root + } elif segment[:2] == ns_selector: # check for namespace prefixed by '++'