Skip to content

Commit 244151f

Browse files
committed
Fix crash with objects and symbols
1 parent 9979af7 commit 244151f

File tree

12 files changed

+93
-12
lines changed

12 files changed

+93
-12
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- '0.8'
4-
- '0.10'
5-
- '0.12'
6-
- 'iojs'
3+
- '4'
4+
- '6'
5+
- '8'
6+
- '10'

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v0.1.27 - 27 Jun 2018
2+
3+
- Handle objects & symbols causing crash in driver 'escapeVal' (#54)
4+
15
### v0.1.26 - 16 May 2015
26

37
- Add support for SELECT TOP construct for mssql dialect for limit (#41)

lib/Dialects/mssql.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.escapeId = function () {
3030
};
3131

3232
exports.escapeVal = function (val, timeZone) {
33-
if (val === undefined || val === null) {
33+
if (val === undefined || val === null || typeof val === "symbol") {
3434
return 'NULL';
3535
}
3636

@@ -60,6 +60,10 @@ exports.escapeVal = function (val, timeZone) {
6060
return val ? 1 : 0;
6161
case "function":
6262
return val(exports);
63+
case "string":
64+
break;
65+
default:
66+
val = JSON.stringify(val);
6367
}
6468

6569
return "'" + val.replace(/\'/g, "''") + "'";

lib/Dialects/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.escapeId = function () {
3030
};
3131

3232
exports.escapeVal = function (val, timeZone) {
33-
if (val === undefined || val === null) {
33+
if (val === undefined || val === null || typeof val === "symbol") {
3434
return 'NULL';
3535
}
3636

lib/Dialects/postgresql.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ exports.escapeId = function () {
3030
};
3131

3232
exports.escapeVal = function (val, timeZone) {
33-
if (val === undefined || val === null) {
33+
if (val === undefined || val === null || typeof val === "symbol") {
3434
return 'NULL';
3535
}
3636

@@ -60,6 +60,10 @@ exports.escapeVal = function (val, timeZone) {
6060
return val ? "true" : "false";
6161
case "function":
6262
return val(exports);
63+
case "string":
64+
break;
65+
default:
66+
val = JSON.stringify(val);
6367
}
6468
// No need to escape backslashes with default PostgreSQL 9.1+ config.
6569
// Google 'postgresql standard_conforming_strings' for details.

lib/Dialects/sqlite.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ exports.escape = function (query, args) {
1818
exports.escapeId = require("./mysql").escapeId;
1919

2020
exports.escapeVal = function (val, timeZone) {
21-
if (val === undefined || val === null) {
21+
if (val === undefined || val === null || typeof val === "symbol") {
2222
return 'NULL';
2323
}
2424

@@ -48,6 +48,10 @@ exports.escapeVal = function (val, timeZone) {
4848
return val ? 1 : 0;
4949
case "function":
5050
return val(exports);
51+
case "string":
52+
break;
53+
default:
54+
val = JSON.stringify(val);
5155
}
5256

5357
// No need to escape backslashes with default PostgreSQL 9.1+ config.

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
"keywords": [
66
"sql",
77
"query"
8-
],
9-
"version": "0.1.26",
8+
],
9+
"version": "0.1.27",
1010
"license": "MIT",
1111
"repository": {
1212
"url": "http://github.com/dresende/node-sql-query"
1313
},
1414
"contributors": [
15-
{ "name" : "Benjamin Pannell", "email" : "[email protected]" },
16-
{ "name" : "Arek W" }
15+
{
16+
"name": "Benjamin Pannell",
17+
"email": "[email protected]"
18+
},
19+
{
20+
"name": "Arek W"
21+
}
1722
],
1823
"scripts": {
1924
"test": "make"

test/integration/test-dialect-mssql.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ assert.equal(
6969
"0"
7070
);
7171

72+
assert.equal(
73+
dialect.escapeVal({ key: 'value' }),
74+
"'{\"key\":\"value\"}'"
75+
);
76+
77+
assert.equal(
78+
dialect.escapeVal(Symbol("why does this exist")),
79+
"NULL"
80+
)
81+
7282
assert.equal(
7383
dialect.escapeVal(new Date(d.getTime() + tzOffsetMillis)),
7484
"'2013-09-04 19:15:11.133'"

test/integration/test-dialect-mysql.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ assert.equal(
6969
"false"
7070
);
7171

72+
assert.equal(
73+
dialect.escapeVal({ key: 'value' }),
74+
"`key` = 'value'"
75+
);
76+
77+
assert.equal(
78+
dialect.escapeVal(Symbol("why does this exist")),
79+
"NULL"
80+
)
81+
7282
assert.equal(
7383
dialect.escapeVal(new Date(d.getTime() + tzOffsetMillis)),
7484
"'2013-09-04 19:15:11.133'"

0 commit comments

Comments
 (0)