From e536ed166195e506784290433d16d8aa594e8001 Mon Sep 17 00:00:00 2001 From: June Kelly Date: Thu, 24 Mar 2022 09:18:49 +0000 Subject: [PATCH] Merge pull request #7125 from overleaf/jk-project-rename-strip-ends [web] Rename project: trim whitespace on ends GitOrigin-RevId: 2499d9e206ed5c929870a0f50cccd07ce3ec5ba7 --- .../app/src/Features/Project/ProjectDetailsHandler.js | 1 + .../unit/src/Project/ProjectDetailsHandlerTests.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/services/web/app/src/Features/Project/ProjectDetailsHandler.js b/services/web/app/src/Features/Project/ProjectDetailsHandler.js index 4bc932bdba..6abd6a7c68 100644 --- a/services/web/app/src/Features/Project/ProjectDetailsHandler.js +++ b/services/web/app/src/Features/Project/ProjectDetailsHandler.js @@ -97,6 +97,7 @@ async function setProjectDescription(projectId, description) { } } async function renameProject(projectId, newName) { + newName = newName.trim() await validateProjectName(newName) logger.log({ projectId, newName }, 'renaming project') let project diff --git a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js index a03bb9d6a9..067876c413 100644 --- a/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js +++ b/services/web/test/unit/src/Project/ProjectDetailsHandlerTests.js @@ -186,6 +186,17 @@ describe('ProjectDetailsHandler', function () { expect(this.TpdsUpdateSender.promises.moveEntity).not.to.have.been.called expect(this.ProjectModel.updateOne).not.to.have.been.called }) + + it('should trim whitespace around name', async function () { + await this.handler.promises.renameProject( + this.project._id, + ` ${this.newName} ` + ) + expect(this.ProjectModel.updateOne).to.have.been.calledWith( + { _id: this.project._id }, + { name: this.newName } + ) + }) }) describe('validateProjectName', function () {