Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/companion: fix 500 when file name contains non-ASCII chars #4493

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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