Skip to content

Commit

Permalink
@uppy/companion: fix 500 when file name contains non-ASCII chars (#4493)
Browse files Browse the repository at this point in the history
* @uppy/companion: fix 500 when file name contains non-ASCII chars

* Update packages/@uppy/companion/src/server/controllers/s3.js

* fixup! @uppy/companion: fix 500 when file name contains non-ASCII chars

* we need a lint rule for this
  • Loading branch information
aduh95 authored Jun 13, 2023
1 parent b8fe961 commit f07697e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Binary file not shown.
9 changes: 9 additions & 0 deletions e2e/cypress/integration/dashboard-aws-multipart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ describe('Dashboard with @uppy/aws-s3-multipart', () => {
cy.wait(['@post', '@get', '@put'])
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})
it('should upload Russian poem image successfully', () => {
const fileName = '١٠ كم мест для Нью-Йорке.pdf'
cy.get('@file-input').selectFile(`cypress/fixtures/images/${fileName}`, { force:true })

cy.get('.uppy-StatusBar-actionBtn--upload').click()
cy.wait(['@post', '@get', '@put'])
cy.get('.uppy-Dashboard-Item-name').should('contain', fileName)
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Complete')
})

it('should handle retry request gracefully', () => {
cy.get('@file-input').selectFile('cypress/fixtures/images/cat.jpg', { force:true })
Expand Down
10 changes: 9 additions & 1 deletion packages/@uppy/companion/src/server/controllers/s3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const express = require('express')

function rfc2047Encode (data) {
// eslint-disable-next-line no-param-reassign
data = `${data}`
// eslint-disable-next-line no-control-regex
if (/^[\x00-\x7F]*$/.test(data)) return data // we return ASCII as is
return `=?UTF-8?B?${Buffer.from(data).toString('base64')}?=` // We encode non-ASCII strings
}

module.exports = function s3 (config) {
if (typeof config.acl !== 'string' && config.acl != null) {
throw new TypeError('s3: The `acl` option must be a string or null')
Expand Down Expand Up @@ -102,7 +110,7 @@ module.exports = function s3 (config) {
Bucket: config.bucket,
Key: key,
ContentType: type,
Metadata: metadata,
Metadata: Object.fromEntries(Object.entries(metadata).map(entry => entry.map(rfc2047Encode))),
}

if (config.acl != null) params.ACL = config.acl
Expand Down

0 comments on commit f07697e

Please sign in to comment.