diff --git a/lib-es5/utils/encoding/base64EncodeURL.js b/lib-es5/utils/encoding/base64EncodeURL.js index be9d5f4f..b0a3b2a9 100644 --- a/lib-es5/utils/encoding/base64EncodeURL.js +++ b/lib-es5/utils/encoding/base64EncodeURL.js @@ -10,7 +10,9 @@ function base64EncodeURL(sourceUrl) { // ignore errors } sourceUrl = encodeURI(sourceUrl); - return base64Encode(sourceUrl); + return base64Encode(sourceUrl).replace(/\+/g, '-') // Convert '+' to '-' + .replace(/\//g, '_') // Convert '/' to '_' + .replace(/=+$/, ''); // Remove ending '='; } module.exports.base64EncodeURL = base64EncodeURL; \ No newline at end of file diff --git a/lib-es5/utils/index.js b/lib-es5/utils/index.js index 92d60496..79c83afd 100644 --- a/lib-es5/utils/index.js +++ b/lib-es5/utils/index.js @@ -173,9 +173,8 @@ function process_custom_function(customFunction) { return customFunction; } if (customFunction.function_type === "remote") { - var encodedSource = base64EncodeURL(customFunction.source).replace(/\+/g, '-') // Convert '+' to '-' - .replace(/\//g, '_') // Convert '/' to '_' - .replace(/=+$/, ''); // Remove ending '=' + var encodedSource = base64EncodeURL(customFunction.source); + return [customFunction.function_type, encodedSource].join(":"); } return [customFunction.function_type, customFunction.source].join(":"); diff --git a/lib/utils/encoding/base64EncodeURL.js b/lib/utils/encoding/base64EncodeURL.js index 786585fc..738a789f 100644 --- a/lib/utils/encoding/base64EncodeURL.js +++ b/lib/utils/encoding/base64EncodeURL.js @@ -7,7 +7,10 @@ function base64EncodeURL(sourceUrl) { // ignore errors } sourceUrl = encodeURI(sourceUrl); - return base64Encode(sourceUrl); + return base64Encode(sourceUrl) + .replace(/\+/g, '-') // Convert '+' to '-' + .replace(/\//g, '_') // Convert '/' to '_' + .replace(/=+$/, ''); // Remove ending '='; } diff --git a/lib/utils/index.js b/lib/utils/index.js index eb3ff010..8719daad 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -156,10 +156,8 @@ function process_custom_function(customFunction) { return customFunction; } if (customFunction.function_type === "remote") { - const encodedSource = base64EncodeURL(customFunction.source) - .replace(/\+/g, '-') // Convert '+' to '-' - .replace(/\//g, '_') // Convert '/' to '_' - .replace(/=+$/, ''); // Remove ending '=' + const encodedSource = base64EncodeURL(customFunction.source); + return [customFunction.function_type, encodedSource].join(":"); } return [customFunction.function_type, customFunction.source].join(":"); diff --git a/test/integration/api/uploader/uploader_spec.js b/test/integration/api/uploader/uploader_spec.js index ebecd4c1..cb198519 100644 --- a/test/integration/api/uploader/uploader_spec.js +++ b/test/integration/api/uploader/uploader_spec.js @@ -99,6 +99,8 @@ describe("uploader", function () { }); }); + + it("should successfully override original_filename", function () { return cloudinary.v2.uploader.upload("http://cloudinary.com/images/old_logo.png", { filename_override: 'overridden' @@ -116,6 +118,17 @@ describe("uploader", function () { }); }); + it('should allow upload with url safe base64 in overlay', function () { + const overlayUrl = 'https://res.cloudinary.com/demo/image/upload/logos/cloudinary_full_logo_white_small.png'; + const baseImageUrl ='http://cloudinary.com/images/old_logo.png'; + + const options = {transformation: {overlay: { url: overlayUrl }}}; + return cloudinary.v2.uploader.upload(baseImageUrl, options) + .then((result) => { + expect(result).to.have.key("created_at"); + }); + }); + describe("remote urls ", function () { const mocked = helper.mockTest(); it("should send s3:// URLs to server", function () { diff --git a/test/utils/utils_spec.js b/test/utils/utils_spec.js index f42a60b5..36806165 100644 --- a/test/utils/utils_spec.js +++ b/test/utils/utils_spec.js @@ -759,18 +759,18 @@ describe("utils", function () { resource_type: "fetch", url: "http://cloudinary.com/images/old_logo.png" }, - "fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc=" + "fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc" ], [ "fetch remote UTF", { url: "https://upload.wikimedia.org/wikipedia/commons/2/2b/고창갯벌.jpg" }, - "fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEvY29tbW9ucy8yLzJiLyVFQSVCMyVBMCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc=" + "fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEvY29tbW9ucy8yLzJiLyVFQSVCMyVBMCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc" ], ["fetch explicit", "fetch:http://cloudinary.com/images/old_logo.png", - "fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc="] + "fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc"] ]; [ {