Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33d69e5

Browse files
committed
Fixed issue with build_where_clause and build_choose_clause.
1 parent 41f42b8 commit 33d69e5

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
========
33

4+
* 0.5.3 (October 14th, 2016)
5+
* Fixed issue in build_choose_clause and build_where_clause that caused single quotes to not be escaped.
6+
47
* 0.5.2 (October 14th, 2016)
58
* Fixed issue on UpdateMixin.
69
* Fixed issue with CashBackInfo.

quickbooks/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def build_where_clause(**kwargs):
99

1010
for key, value in kwargs.items():
1111
if isinstance(value, six.string_types):
12-
where.append("{0} = '{1}'".format(key, value.replace("'", "\'")))
12+
where.append("{0} = '{1}'".format(key, value.replace(r"'", r"\'")))
1313
else:
1414
where.append("{0} = {1}".format(key, value))
1515

@@ -26,7 +26,7 @@ def build_choose_clause(choices, field):
2626

2727
for choice in choices:
2828
if isinstance(choice, six.string_types):
29-
where.append("'{0}'".format(choice.replace("'", "\'")))
29+
where.append("'{0}'".format(choice.replace(r"'", r"\'")))
3030
else:
3131
where.append("{0}".format(choice))
3232

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def read(*parts):
1010
return fp.read()
1111

1212

13-
VERSION = (0, 5, 2)
13+
VERSION = (0, 5, 3)
1414
version = '.'.join(map(str, VERSION))
1515

1616
setup(

tests/unit/test_utils.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44

55
class UtilsTests(unittest.TestCase):
6-
def setup(self):
7-
pass
8-
96
def test_build_where_clause(self):
10-
where_clause = utils.build_where_clause(field1=1, field2="value2")
11-
12-
self.assertTrue(where_clause, "WHERE field1 = 1 AND field2 = 'value2")
7+
where_clause = utils.build_where_clause(field1=1, field2="Someone's Company")
8+
self.assertEqual(where_clause, "field2 = 'Someone\\\'s Company' AND field1 = 1")
139

1410
def test_build_where_clause_integers(self):
1511
where_clause = utils.build_choose_clause(choices=[1, 2], field="field1")
1612

17-
self.assertTrue(where_clause, "WHERE field1 in (1, 2)")
13+
self.assertEqual(where_clause, "field1 in (1, 2)")
1814

1915
def test_build_where_clause_strings(self):
2016
where_clause = utils.build_choose_clause(choices=["val1", "val2"], field="field1")
2117

22-
self.assertTrue(where_clause, "WHERE field1 in ('val1', 'val2')")
18+
self.assertEqual(where_clause, "field1 in ('val1', 'val2')")
19+
20+
def test_build_where_clause_quoted_value(self):
21+
where_clause = utils.build_choose_clause(choices=["val1", "Someone's Company"], field="field1")
22+
23+
self.assertEqual(where_clause, "field1 in ('val1', 'Someone\\\'s Company')")

0 commit comments

Comments
 (0)