Skip to content

Commit

Permalink
fixup: url encode header response elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Toozs committed Jul 18, 2024
1 parent d09a42d commit 2a7d4cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/api/objectPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ function objectPost(authInfo, request, streamingV4Params, log, callback) {
});
if (storingResult) {
// ETag's hex should always be enclosed in quotes
responseHeaders.Key = request.formData.key;
responseHeaders.location = `/${bucketName}/${request.formData.key}`;
responseHeaders.location = `/${bucketName}/${encodeURIComponent(request.formData.key)}`;
responseHeaders.Bucket = bucketName;
responseHeaders.ETag = `"${storingResult.contentMD5}"`;
}
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/aws-node-sdk/test/object/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,41 @@ describe('POST object', () => {
});
});

it('should handle url invalid characters in keys', done => {
const { url } = testContext;
const fields = calculateFields(ak, sk, [{ key: 'key with spaces' }]);
const formData = new FormData();
const encodedKey = 'key%20with%20spaces'; // Expected URL-encoded key

fields.forEach(field => {
formData.append(field.name, field.value);
});

formData.append('file', fileBuffer, { filename });

formData.getLength((err, length) => {
if (err) {
return done(err);
}

return axios.post(url, formData, {
headers: {
...formData.getHeaders(),
'Content-Length': length,
},
})
.then(response => {
assert.equal(response.status, 204);
assert.equal(response.headers.location, `/${bucketName}/${encodedKey}`);
assert.equal(response.headers.bucket, bucketName);
done();
})
.catch(err => {
done(err);
});
});
});

it('should handle error when bucket does not exist', done => {
const fakeBucketName = generateBucketName();
const tempUrl = `${config.endpoint}/${fakeBucketName}`;
Expand Down

0 comments on commit 2a7d4cf

Please sign in to comment.