diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index c68e6e271..0b5a1a7cb 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -387,15 +387,10 @@ Pad.prototype.init = async function (text, authorId = '') { } } else { if (text == null) { - const context = { - pad: this, - authorId, - type: 'text', - content: exports.cleanText(settings.defaultPadText), - }; + const context = {pad: this, authorId, type: 'text', content: settings.defaultPadText}; await hooks.aCallAll('padDefaultContent', context); if (context.type !== 'text') throw new Error(`unsupported content type: ${context.type}`); - text = context.content; + text = exports.cleanText(context.content); } const firstChangeset = Changeset.makeSplice('\n', 0, 0, text); await this.appendRevision(firstChangeset, authorId); diff --git a/src/tests/backend/specs/Pad.js b/src/tests/backend/specs/Pad.js index 0e385097e..ec5c24631 100644 --- a/src/tests/backend/specs/Pad.js +++ b/src/tests/backend/specs/Pad.js @@ -118,5 +118,17 @@ describe(__filename, function () { pad = await padManager.getPad(padId); assert.equal(pad.text(), `${want}\n`); }); + + it('cleans provided content', async function () { + const input = 'foo\r\nbar\r\tbaz'; + const want = 'foo\nbar\n baz'; + assert.notEqual(want, settings.defaultPadText); + plugins.hooks.padDefaultContent.push({hook_fn: async (hookName, ctx) => { + ctx.type = 'text'; + ctx.content = input; + }}); + pad = await padManager.getPad(padId); + assert.equal(pad.text(), `${want}\n`); + }); }); });