Skip to content

Commit

Permalink
avoid UnicodeEncodeError when params contains non ascii characters
Browse files Browse the repository at this point in the history
  • Loading branch information
gawel committed Jan 21, 2014
1 parent 9c34e8b commit ae5c63a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions ckan/controllers/feed.py
Expand Up @@ -21,7 +21,6 @@
# TODO fix imports
import logging
import urlparse
from urllib import urlencode

import webhelpers.feedgenerator
from pylons import config
Expand Down Expand Up @@ -277,8 +276,6 @@ def custom(self):
search_params[param] = value
fq += ' %s:"%s"' % (param, value)

search_url_params = urlencode(search_params)

try:
page = int(request.params.get('page', 1))
except ValueError:
Expand Down Expand Up @@ -307,6 +304,9 @@ def custom(self):
controller='feed',
action='custom')

atom_url = h._url_with_params('/feeds/custom.atom',
search_params.items())

alternate_url = self._alternate_url(request.params)

return self.output_feed(results,
Expand All @@ -315,8 +315,7 @@ def custom(self):
' datasets on %s. Custom query: \'%s\'' %
(g.site_title, q),
feed_link=alternate_url,
feed_guid=_create_atom_id
(u'/feeds/custom.atom?%s' % search_url_params),
feed_guid=_create_atom_id(atom_url),
feed_url=feed_url,
navigation_urls=navigation_urls)

Expand Down Expand Up @@ -376,11 +375,7 @@ def _feed_url(self, query, controller, action, **kwargs):
parameters.
"""
path = h.url_for(controller=controller, action=action, **kwargs)
query = [(k, v.encode('utf-8') if isinstance(v, basestring)
else str(v)) for k, v in query.items()]

# a trailing '?' is valid.
return self.base_url + path + u'?' + urlencode(query)
return h._url_with_params(self.base_url + path, query.items())

def _navigation_urls(self, query, controller, action,
item_count, limit, **kwargs):
Expand Down

0 comments on commit ae5c63a

Please sign in to comment.