Skip to content

Commit 03dc88e

Browse files
committed
tests: add escape object toString tests
1 parent 940918b commit 03dc88e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/unit/test-SqlString.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ test('SqlString.escape', {
7878
assert.equal(SqlString.escape({a: {nested: true}}), "`a` = '[object Object]'");
7979
},
8080

81+
'nested objects use toString': function() {
82+
assert.equal(SqlString.escape({a: { toString: function() { return 'foo'; } }}), "`a` = 'foo'");
83+
},
84+
85+
'nested objects use toString is quoted': function() {
86+
assert.equal(SqlString.escape({a: { toString: function() { return "f'oo"; } }}), "`a` = 'f\\'oo'");
87+
},
88+
8189
'arrays are turned into lists': function() {
8290
assert.equal(SqlString.escape([1, 2, 'c']), "1, 2, 'c'");
8391
},
@@ -90,6 +98,10 @@ test('SqlString.escape', {
9098
assert.equal(SqlString.escape([1, {nested: true}, 2]), "1, '[object Object]', 2");
9199
},
92100

101+
'nested objects inside arrays use toString': function() {
102+
assert.equal(SqlString.escape([1, { toString: function() { return 'foo'; } }, 2]), "1, 'foo', 2");
103+
},
104+
93105
'strings are quoted': function() {
94106
assert.equal(SqlString.escape('Super'), "'Super'");
95107
},

0 commit comments

Comments
 (0)