diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 984a4e0a7..0c9a61d90 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -545,6 +545,20 @@ describe('#documents.create', async () => { expect(body.data.text).toBe('# Untitled document'); }); + it('should not allow very long titles', async () => { + const { user, collection } = await seed(); + const res = await server.post('/api/documents.create', { + body: { + token: user.getJwtToken(), + collection: collection.id, + title: + 'This is a really long title that is not acceptable to Outline because it is so ridiculously long that we need to have a limit somewhere', + text: ' ', + }, + }); + expect(res.status).toEqual(400); + }); + it('should create as a child and add to collection if published', async () => { const { user, document, collection } = await seed(); const res = await server.post('/api/documents.create', { diff --git a/server/models/Document.js b/server/models/Document.js index de17335da..4fc51a370 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -83,9 +83,19 @@ const Document = sequelize.define( defaultValue: DataTypes.UUIDV4, primaryKey: true, }, - urlId: { type: DataTypes.STRING, primaryKey: true }, - private: { type: DataTypes.BOOLEAN, defaultValue: true }, - title: DataTypes.STRING, + urlId: { + type: DataTypes.STRING, + primaryKey: true, + }, + title: { + type: DataTypes.STRING, + validate: { + len: { + args: [0, 100], + msg: 'Document title must be less than 100 characters', + }, + }, + }, text: DataTypes.TEXT, revisionCount: { type: DataTypes.INTEGER, defaultValue: 0 }, publishedAt: DataTypes.DATE,