Skip to content

Commit 47e5084

Browse files
committed
Avoids JSON parsing values when they are already objects (and not string buffers) (dresende#168)
1 parent 27b1e03 commit 47e5084

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/Drivers/DML/mysql.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ Driver.prototype.valueToProperty = function (value, property) {
225225
case "boolean":
226226
return !!value;
227227
case "object":
228+
if (typeof value == "object" && !Buffer.isBuffer(value)) {
229+
return value;
230+
}
228231
try {
229232
return JSON.parse(value);
230233
} catch (e) {

lib/Drivers/DML/postgres.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ Driver.prototype.clear = function (table, cb) {
250250
Driver.prototype.valueToProperty = function (value, property) {
251251
switch (property.type) {
252252
case "object":
253+
if (typeof value == "object" && !Buffer.isBuffer(value)) {
254+
return value;
255+
}
253256
try {
254257
return JSON.parse(value);
255258
} catch (e) {

lib/Drivers/DML/sqlite.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ Driver.prototype.valueToProperty = function (value, property) {
198198
case "boolean":
199199
return !!value;
200200
case "object":
201+
if (typeof value == "object" && !Buffer.isBuffer(value)) {
202+
return value;
203+
}
201204
try {
202205
return JSON.parse(value);
203206
} catch (e) {

0 commit comments

Comments
 (0)