Skip to content

Commit 6794796

Browse files
fix: decoding transformation string before sending in upload payload (#662)
* fix: decoding transformation string before sending in upload payload
1 parent bf23c5f commit 6794796

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function build_upload_params(options) {
406406
responsive_breakpoints: utils.generate_responsive_breakpoints_string(options.responsive_breakpoints),
407407
return_delete_token: utils.as_safe_bool(options.return_delete_token),
408408
timestamp: options.timestamp || exports.timestamp(),
409-
transformation: utils.generate_transformation_string(clone(options)),
409+
transformation: decodeURIComponent(utils.generate_transformation_string(clone(options))),
410410
type: options.type,
411411
unique_filename: utils.as_safe_bool(options.unique_filename),
412412
upload_preset: options.upload_preset,

test/integration/api/uploader/uploader_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ describe("uploader", function () {
9191
sinon.assert.calledWith(writeSpy, sinon.match(helper.uploadParamMatcher("metadata", METADATA_SAMPLE_DATA_ENCODED)));
9292
});
9393
});
94+
it('should upload a file with correctly encoded transformation string', () => {
95+
return helper.provideMockObjects(function (mockXHR, writeSpy, requestSpy) {
96+
const uploadResult = cloudinary.v2.uploader.upload('irrelevant', { transformation: { overlay: { text: 'test / 火' } } });
97+
sinon.assert.calledWith(writeSpy, sinon.match(helper.uploadParamMatcher('transformation', 'l_text:test %2F 火')));
98+
});
99+
});
100+
it('should upload a file with correctly encoded transformation string incl 4bytes characters', () => {
101+
return helper.provideMockObjects(function (mockXHR, writeSpy, requestSpy) {
102+
cloudinary.v2.uploader.upload('irrelevant', { transformation: { overlay: { text: 'test 𩸽 🍺' } } })
103+
.then((uploadResult) => {
104+
sinon.assert.calledWith(writeSpy, sinon.match(helper.uploadParamMatcher('transformation', 'l_text:test 𩸽 🍺')));
105+
expect(uploadResult).to.have.key("created_at");
106+
});
107+
});
108+
});
94109
it("should successfully upload url", function () {
95110
return cloudinary.v2.uploader.upload("https://cloudinary.com/images/old_logo.png", {
96111
tags: UPLOAD_TAGS

0 commit comments

Comments
 (0)