Skip to content

Commit

Permalink
fix: encode filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and Zé Bateira committed Oct 15, 2021
1 parent 4d3f1b1 commit 1fd62a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/website/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ export async function getUploads({ size, before, sortBy, sortOrder }) {
throw new Error(`failed to get uploads: ${await res.text()}`)
}

return res.json()
// Sanatize data
const data = (await res.json()).map(upload => ({
...upload,
name: decodeURIComponent(upload.name)
}))

return data
}

/**
Expand Down Expand Up @@ -159,7 +165,7 @@ export async function deleteUpload (cid) {
Authorization: 'Bearer ' + (await getToken()),
},
body: JSON.stringify({
name
name: encodeURIComponent(name)
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/website/pages/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function Upload() {
try {
let totalBytesSent = 0;
await client.put([file], {
name: file.name,
name: encodeURIComponent(file.name),
onStoredChunk: (size) => {
totalBytesSent += size;
setPercentComplete(Math.round((totalBytesSent / file.size) * 100));
Expand Down Expand Up @@ -98,7 +98,7 @@ export default function Upload() {
/>
<div className="flex items-center border-w3storage-red border-dashed border-2 p-3">
<Button variant='light' className='border border-w3storage-purple focus:border-w3storage-purple' onClick={openInput}>Choose File</Button>
<p className="px-4">{ inputFile.name.length > 0 ? inputFile.name : 'No file chosen'}</p>
<p className="px-4">{ inputFile.name.length > 0 ? decodeURIComponent(inputFile.name) : 'No file chosen'}</p>
</div>
</div>
<div>
Expand Down

0 comments on commit 1fd62a0

Please sign in to comment.