Просмотр исходного кода

Merge pull request #12654 from overleaf/em-td-upload-filename-encoding

Fix filename encoding of project and file uploads

GitOrigin-RevId: e718c8f8f376772ee13c50c82d26848977e16eef
Eric Mc Sween 3 лет назад
Родитель
Сommit
5b804ceefd

+ 3 - 3
services/web/app/src/Features/Uploads/ProjectUploadController.js

@@ -39,8 +39,8 @@ module.exports = ProjectUploadController = {
   uploadProject(req, res, next) {
     const timer = new metrics.Timer('project-upload')
     const userId = SessionManager.getLoggedInUserId(req.session)
-    const { originalname, path } = req.file
-    const name = Path.basename(originalname, '.zip')
+    const { path } = req.file
+    const name = Path.basename(req.body.name, '.zip')
     return ProjectUploadManager.createProjectFromZipArchive(
       userId,
       name,
@@ -73,7 +73,7 @@ module.exports = ProjectUploadController = {
 
   uploadFile(req, res, next) {
     const timer = new metrics.Timer('file-upload')
-    const name = req.file != null ? req.file.originalname : undefined
+    const name = req.body.name
     const path = req.file != null ? req.file.path : undefined
     const projectId = req.params.Project_id
     const { folder_id: folderId } = req.query

+ 1 - 0
services/web/test/acceptance/src/ProjectDuplicateNameTests.js

@@ -189,6 +189,7 @@ describe('ProjectDuplicateNames', function () {
                 qqfilename: 'frog.jpg',
               },
               formData: {
+                name: 'frog.jpg',
                 qqfile: {
                   value: fs.createReadStream(
                     Path.join(__dirname, '/../files/1pixel.png')

+ 1 - 0
services/web/test/acceptance/src/ProjectStructureTests.js

@@ -105,6 +105,7 @@ describe('ProjectStructureChanges', function () {
       {
         uri: 'project/new/upload',
         formData: {
+          name: zipFilename,
           qqfile: zipFile,
         },
       },

+ 1 - 0
services/web/test/acceptance/src/helpers/User.js

@@ -492,6 +492,7 @@ class User {
           folder_id: String(folderId),
         },
         formData: {
+          name,
           qqfile: {
             value: imageFile,
             options: {

+ 7 - 3
services/web/test/unit/src/Uploads/ProjectUploadControllerTests.js

@@ -61,7 +61,9 @@ describe('ProjectUploadController', function () {
       this.name = 'filename.zip'
       this.req.file = {
         path: this.path,
-        originalname: this.name,
+      }
+      this.req.body = {
+        name: this.name,
       }
       this.req.session = {
         user: {
@@ -165,7 +167,9 @@ describe('ProjectUploadController', function () {
       this.name = 'filename.png'
       this.req.file = {
         path: this.path,
-        originalname: this.name,
+      }
+      this.req.body = {
+        name: this.name,
       }
       this.req.session = {
         user: {
@@ -257,7 +261,7 @@ describe('ProjectUploadController', function () {
 
     describe('with an invalid filename', function () {
       beforeEach(function () {
-        this.req.file.originalname = ''
+        this.req.body.name = ''
         return this.ProjectUploadController.uploadFile(this.req, this.res)
       })