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

Decode x-amz-copy-source to support spaces & special characters #207

Merged
merged 1 commit into from
Apr 6, 2018
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
2 changes: 1 addition & 1 deletion lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = function(rootDirectory, logger, indexDocument, errorDocument) {
}

function copyObject(req, res) {
let copySource = req.headers["x-amz-copy-source"];
let copySource = decodeURI(req.headers["x-amz-copy-source"]);
copySource = copySource.startsWith("/") ? copySource.slice(1) : copySource;
let [srcBucket, ...srcKey] = copySource.split("/");
srcKey = srcKey.join("/");
Expand Down
25 changes: 25 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,31 @@ describe("S3rver Tests", function() {
expect(object.ContentType).to.equal("image/jpeg");
});

it("should copy an object using spaces/unicode chars in keys", function*() {
const srcKey = "awesome 驚くばかり.jpg";
const destKey = "new 新しい.jpg";

const file = path.join(__dirname, "resources/image0.jpg");
const data = yield s3Client
.putObject({
Bucket: buckets[0],
Key: srcKey,
Body: yield fs.readFile(file),
ContentType: "image/jpeg"
})
.promise();
expect(data.ETag).to.match(/"[a-fA-F0-9]{32}"/);
const copyResult = yield s3Client
.copyObject({
Bucket: buckets[0],
Key: destKey,
CopySource: "/" + buckets[0] + "/" + encodeURI(srcKey)
})
.promise();
expect(copyResult.ETag).to.equal(data.ETag);
expect(moment(copyResult.LastModified).isValid()).to.be.true;
});

it("should update the metadata of an image object", function*() {
const srcKey = "image";
const destKey = "image/jamie";
Expand Down