Skip to content

Commit

Permalink
Merge pull request #3 from podhmo/fix/escape
Browse files Browse the repository at this point in the history
a query with  range of values, over escaped expression is generated.L
  • Loading branch information
tell-k committed Nov 20, 2015
2 parents 68db143 + e57a8b4 commit 088672d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions csquery/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ def format_value(value):
if (value.startswith('(') and value.endswith(')'))\
or (value.startswith('{') and value.endswith(']'))\
or (value.startswith('[') and value.endswith('}'))\
or (value.startswith('[') and value.endswith(']'))\
or ('=' in value):
or (value.startswith('[') and value.endswith(']')):
return six.text_type(value)
elif '=' in value:
return six.text_type(escape(value))
except AttributeError:
return six.text_type(value)
Expand Down
25 changes: 24 additions & 1 deletion tests/test_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def test_it(self):
)
assert "'test'" == self._call_fut('test')

# escape value
def test_it_for_escape(self):
from csquery.structured import Expression, field

assert r"(and title:'st\\ar')" == self._call_fut(
Expression('and', title=r'st\ar')
)
Expand All @@ -107,6 +109,27 @@ def test_it(self):
field("Alec'Guinness", 'actors')
)

def test_it_for_escape__with_range_values(self):
from csquery.structured import and_

assert "(and release_date:[\'2000-01-01T00:00:00Z\', \'2010-01-01T00:00:00Z\'})" == self._call_fut(
and_(release_date="['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'}")
)
assert "(and (and release_date:[\'2000-01-01T00:00:00Z\', \'2010-01-01T00:00:00Z\'}))" == self._call_fut(
and_(and_(release_date="['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'}"))
)

assert "(and (and release_date:[\'2000-01-01T00:00:00Z\', \'2010-01-01T00:00:00Z\'}))" == self._call_fut(
and_(and_(release_date="['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'}"))
)

assert "(and _id:['tt1000000','tt1005000'])" == self._call_fut(
and_(_id="['tt1000000','tt1005000']")
)
assert "(and _id:['tt\'1000000','tt\'1005000'])" == self._call_fut(
and_(_id="['tt\'1000000','tt\'1005000']")
)

def test_it__with_multi_encoding(self):
from csquery.structured import Expression
import six
Expand Down

0 comments on commit 088672d

Please sign in to comment.