Skip to content

Commit

Permalink
Validate url path
Browse files Browse the repository at this point in the history
  • Loading branch information
audiodude committed Jul 21, 2023
1 parent 9ba58fc commit dd77154
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions wp1/selection/models/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ def validate(self, **params):
if 'project' not in params:
return ('', params['url'], ['Missing project parameter'])

if params['project'] not in params['url']:
parsed_url = urllib.parse.urlparse(params['url'])
return ('', params['url'], [
url = params['url']

if params['project'] not in url:
parsed_url = urllib.parse.urlparse(url)
return ('', url, [
'The domain of your URL does not match your '
'selected project (project is: %s, URL has: %s)' %
(params['project'], parsed_url.netloc)
])

if not validators.url(params['url']):
return ('', params['url'], ['That doesn\'t look like a valid URL.'])
if not validators.url(url):
return ('', url, ['That doesn\'t look like a valid URL.'])

if 'wiki/' not in url:
return ('', url, ['Valid book urls include /wiki/.'])

return ('', '', [])

0 comments on commit dd77154

Please sign in to comment.