Skip to content

Commit cee3593

Browse files
XadillaXdougwilson
authored andcommitted
Accept numbers and other value types in escapeId
closes mysqljs#5
1 parent 22797e5 commit cee3593

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Accept numbers and other value types in `escapeId`
45
* Run `buffer.toString()` through escaping
56

67
2.0.1 / 2016-06-06

lib/SqlString.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ SqlString.escapeId = function escapeId(val, forbidQualified) {
2424
}
2525

2626
if (forbidQualified) {
27-
return '`' + val.replace(/`/g, '``') + '`';
27+
return '`' + String(val).replace(/`/g, '``') + '`';
2828
}
2929

30-
return '`' + val.replace(/`/g, '``').replace(/\./g, '`.`') + '`';
30+
return '`' + String(val).replace(/`/g, '``').replace(/\./g, '`.`') + '`';
3131
};
3232

3333
SqlString.escape = function escape(val, stringifyObjects, timeZone) {

test/unit/test-SqlString.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test('SqlString.escapeId', {
77
assert.equal('`id`', SqlString.escapeId('id'));
88
},
99

10+
'value can be a number': function() {
11+
assert.equal('`42`', SqlString.escapeId(42));
12+
},
13+
1014
'value containing escapes is quoted': function() {
1115
assert.equal('`i``d`', SqlString.escapeId('i`d'));
1216
},

0 commit comments

Comments
 (0)