Skip to content

Commit

Permalink
support quoted sort args for backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi authored and amercader committed Sep 2, 2015
1 parent 9d7295b commit 09600a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion ckanext/datastore/helpers.py
Expand Up @@ -99,4 +99,11 @@ def literal_string(s):
"""
Return s as a postgres literal string
"""
return u"'" + s.replace(u"'", u"''") + u"'"
return u"'" + s.replace(u"'", u"''").replace(u'\0', '') + u"'"


def identifier(s):
"""
Return s as a quoted postgres identifier
"""
return u'"' + s.replace(u'"', u'""').replace(u'\0', '') + u'"'
5 changes: 4 additions & 1 deletion ckanext/datastore/plugin.py
Expand Up @@ -357,6 +357,8 @@ def _parse_sort_clause(self, clause, fields_types):
return False

field = clause_match.group(1)
if field[0] == field[-1] == u'"':
field = field[1:-1]
sort = (clause_match.group(3) or u'asc').lower()

if field not in fields_types:
Expand Down Expand Up @@ -460,7 +462,8 @@ def _sort(self, data_dict, fields_types):

for clause in clauses:
field, sort = self._parse_sort_clause(clause, fields_types)
clause_parsed.append(u'"{0}" {1}'.format(field, sort))
clause_parsed.append(
u'{0} {1}'.format(datastore_helpers.identifier(field), sort))

return clause_parsed

Expand Down

0 comments on commit 09600a8

Please sign in to comment.