Guest User

Untitled

a guest
Jan 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. diff --git a/ckan/config/middleware/__init__.py b/ckan/config/middleware/__init__.py
  2. index 73af42fa2..a958d8e42 100644
  3. --- a/ckan/config/middleware/__init__.py
  4. +++ b/ckan/config/middleware/__init__.py
  5. @@ -127,8 +127,19 @@ class AskAppDispatcherMiddleware(object):
  6. * CKAN_CURRENT_URL is set to the current application url
  7. '''
  8.  
  9. + # Ensure URL encoding
  10. + for var in ('PATH_INFO', 'REQUEST_URI', 'QUERY_STRING'):
  11. + val = environ.get(var)
  12. + if val:
  13. + try:
  14. + val.decode('utf-8')
  15. + except UnicodeDecodeError:
  16. + val = val.decode('cp1252').encode('utf-8')
  17. + environ[var] = urllib.quote(val, ':/&=')
  18. +
  19. # We only update once for a request so we can keep
  20. # the language and original url which helps with 404 pages etc
  21. +
  22. if 'CKAN_LANG' not in environ:
  23. path_parts = environ['PATH_INFO'].split('/')
  24. if len(path_parts) > 1 and path_parts[1] in self.locale_list:
  25. @@ -145,15 +156,9 @@ class AskAppDispatcherMiddleware(object):
  26.  
  27. # Current application url
  28. path_info = environ['PATH_INFO']
  29. - # sort out weird encodings
  30. - path_info = \
  31. - '/'.join(urllib.quote(pce, '') for pce in path_info.split('/'))
  32. -
  33. qs = environ.get('QUERY_STRING')
  34.  
  35. if qs:
  36. - # sort out weird encodings
  37. - qs = urllib.quote(qs, '')
  38. environ['CKAN_CURRENT_URL'] = '%s?%s' % (path_info, qs)
  39. else:
  40. environ['CKAN_CURRENT_URL'] = path_info
Add Comment
Please, Sign In to add comment