From a19fc66b3452e0f6397e63fe7a3976c7c8f79ee7 Mon Sep 17 00:00:00 2001 From: Addison Schiller Date: Mon, 11 Sep 2017 13:16:18 -0400 Subject: [PATCH] making changes to undecoded path Breaking up indices to make it easier to read. Fixing edge cases around `?` and when no `?` is present. --- waterbutler/server/api/v1/provider/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/waterbutler/server/api/v1/provider/__init__.py b/waterbutler/server/api/v1/provider/__init__.py index ce265cea3..08bb9c77e 100644 --- a/waterbutler/server/api/v1/provider/__init__.py +++ b/waterbutler/server/api/v1/provider/__init__.py @@ -62,11 +62,17 @@ async def prepare(self, *args, **kwargs): self.auth = await auth_handler.get(self.resource, provider, self.request) self.provider = utils.make_provider(provider, self.auth['auth'], self.auth['credentials'], self.auth['settings']) - # Find start of provider name, and start of ? marker and pull out file name from between them. - self.provider.undecoded_path = self.request.uri[self.request.uri.rfind(self.path_kwargs['provider'] + '/') + (len(self.path_kwargs['provider'])): self.request.uri.rfind("?")] + # Find start of provider name, and start of ? marker and pull out file name from between them. + provider_index = self.request.uri.index(self.path_kwargs['provider'] + '/') + provider_length = (len(self.path_kwargs['provider'])) + end_of_path_index = self.request.uri.find('?') + # If there is no ? in uri, go to end of uri + if end_of_path_index == -1: + end_of_path_index = len(self.request.uri) + + self.provider.undecoded_path = self.request.uri[provider_index + provider_length: end_of_path_index] self.path = await self.provider.validate_v1_path(self.path, **self.arguments) - self.target_path = None # post-validator methods perform validations that expect that the path given in the url has