Skip to content
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
6 changes: 5 additions & 1 deletion lib-es5/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,11 @@ function base_api_url() {

var cloudinary = ensureOption(options, "upload_prefix", UPLOAD_PREFIX);
var cloud_name = ensureOption(options, "cloud_name");
return [cloudinary, "v1_1", cloud_name].concat(path).join("/");
var encode_path = function encode_path(unencoded_path) {
return encodeURIComponent(unencoded_path).replace("'", '%27');
};
var encoded_path = Array.isArray(path) ? path.map(encode_path) : encode_path(path);
return [cloudinary, "v1_1", cloud_name].concat(encoded_path).join("/");
}

function api_url() {
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ function unsigned_url_prefix(
function base_api_url(path= [], options = {}) {
let cloudinary = ensureOption(options, "upload_prefix", UPLOAD_PREFIX);
let cloud_name = ensureOption(options, "cloud_name");
return [cloudinary, "v1_1", cloud_name].concat(path).join("/");
let encode_path = unencoded_path => encodeURIComponent(unencoded_path).replace("'", '%27');
let encoded_path = Array.isArray(path) ? path.map(encode_path) : encode_path(path);
return [cloudinary, "v1_1", cloud_name].concat(encoded_path).join("/");
}

function api_url(action = 'upload', options = {}) {
Expand Down
5 changes: 5 additions & 0 deletions test/utils/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ describe("utils", function () {
type: "youtube"
}, `http://res.cloudinary.com/${cloud_name}/image/youtube/http://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M`, {});
});
it('should escape api urls', function () {
const folderName = "sub^folder's test";
const url = utils.base_api_url(['folders', folderName]);
expect(url).to.match(/folders\/sub%5Efolder%27s%20test$/);
});
});
describe('transformation parameters', function () {
describe("gravity", function () {
Expand Down