diff options
Diffstat (limited to '')
-rw-r--r-- | lib/models/index.js | 7 | ||||
-rw-r--r-- | lib/models/note.js | 15 | ||||
-rw-r--r-- | lib/models/revision.js | 20 |
3 files changed, 35 insertions, 7 deletions
diff --git a/lib/models/index.js b/lib/models/index.js index de6cd13c..6d0fd3c3 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -20,6 +20,13 @@ if (config.dburl) else sequelize = new Sequelize(dbconfig.database, dbconfig.username, dbconfig.password, dbconfig); +// [Postgres] Handling NULL bytes +// https://github.com/sequelize/sequelize/issues/6485 +function stripNullByte(value) { + return value ? value.replace(/\u0000/g, "") : value; +} +sequelize.stripNullByte = stripNullByte; + var db = {}; fs diff --git a/lib/models/note.js b/lib/models/note.js index 81de991f..37d26ec0 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -52,13 +52,22 @@ module.exports = function (sequelize, DataTypes) { defaultValue: 0 }, title: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('title', sequelize.stripNullByte(value)); + } }, content: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('content', sequelize.stripNullByte(value)); + } }, authorship: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('authorship', JSON.stringify(value)); + } }, lastchangeAt: { type: DataTypes.DATE diff --git a/lib/models/revision.js b/lib/models/revision.js index 6f44cf1d..adc651f1 100644 --- a/lib/models/revision.js +++ b/lib/models/revision.js @@ -59,19 +59,31 @@ module.exports = function (sequelize, DataTypes) { defaultValue: Sequelize.UUIDV4 }, patch: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('patch', sequelize.stripNullByte(value)); + } }, lastContent: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('lastContent', sequelize.stripNullByte(value)); + } }, content: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('content', sequelize.stripNullByte(value)); + } }, length: { type: DataTypes.INTEGER }, authorship: { - type: DataTypes.TEXT + type: DataTypes.TEXT, + set: function (value) { + this.setDataValue('authorship', value ? JSON.stringify(value) : value); + } } }, { classMethods: { |