Skip to content

Commit a8717a5

Browse files
Added a 'undecoded_url' variable to addon providers.
Currently, a URL can get encoded and decoded many times. This can cause the original name of a file to be near impossible to figure out if it uses special characters. This variable will help solve this problem.
1 parent 879aedd commit a8717a5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

waterbutler/core/provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self, auth: dict,
9999
self.auth = auth
100100
self.credentials = credentials
101101
self.settings = settings
102+
self.undecoded_path = None
102103

103104
self.provider_metrics = MetricsRecord('provider')
104105
self.provider_metrics.add('auth', auth)

waterbutler/server/api/v1/provider/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ async def prepare(self, *args, **kwargs):
6262

6363
self.auth = await auth_handler.get(self.resource, provider, self.request)
6464
self.provider = utils.make_provider(provider, self.auth['auth'], self.auth['credentials'], self.auth['settings'])
65-
self.path = await self.provider.validate_v1_path(self.path, **self.arguments)
6665

66+
# Find start of provider name, and start of ? marker and pull out file name from between them.
67+
provider_index = self.request.uri.index(self.path_kwargs['provider'] + '/')
68+
provider_length = (len(self.path_kwargs['provider']))
69+
end_of_path_index = self.request.uri.find('?')
70+
# If there is no ? in uri, go to end of uri
71+
if end_of_path_index == -1:
72+
end_of_path_index = len(self.request.uri)
73+
74+
self.provider.undecoded_path = self.request.uri[provider_index + provider_length: end_of_path_index]
75+
self.path = await self.provider.validate_v1_path(self.path, **self.arguments)
6776
self.target_path = None
6877

6978
# post-validator methods perform validations that expect that the path given in the url has

0 commit comments

Comments
 (0)