Skip to content

Commit 43212e2

Browse files
authored
fixed font_family encoding (#498)
* fixed font_family encoding
1 parent e0ab1a0 commit 43212e2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib-es5/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ function url(public_id) {
826826
var prefix = unsigned_url_prefix(public_id, cloud_name, private_cdn, cdn_subdomain, secure_cdn_subdomain, cname, secure, secure_distribution);
827827
var resultUrl = [prefix, resource_type, type, signature, transformation, version, public_id].filter(function (part) {
828828
return part != null && part !== '';
829-
}).join('/').replace(' ', '%20');
829+
}).join('/').replace(/ /g, '%20');
830830
if (sign_url && !isEmpty(auth_token)) {
831831
auth_token.url = urlParse(resultUrl).path;
832832
var token = generate_token(auth_token);

lib/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ function url(public_id, options = {}) {
758758
);
759759
let resultUrl = [prefix, resource_type, type, signature, transformation, version, public_id].filter(function (part) {
760760
return (part != null) && part !== '';
761-
}).join('/').replace(' ', '%20');
761+
}).join('/').replace(/ /g, '%20');
762762
if (sign_url && !isEmpty(auth_token)) {
763763
auth_token.url = urlParse(resultUrl).path;
764764
let token = generate_token(auth_token);

test/utils/utils_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,25 @@ describe("utils", function () {
797797
expect(["test", opt]).to.produceUrl(`http://res.cloudinary.com/${cloud_name}/image/upload/h_100,${letter}_text:hello,w_100/test`).and.emptyOptions();
798798
});
799799
});
800+
it("should encode font_family with %20", () => {
801+
let url = cloudinary.utils.url("sample",
802+
{
803+
overlay: {
804+
text: "sample text",
805+
font_family: "Times New Roman",
806+
font_size: "18"
807+
}
808+
});
809+
expect(url).to.eql(`http://res.cloudinary.com/${cloud_name}/image/upload/l_text:Times%20New%20Roman_18:sample%20text/sample`);
810+
});
811+
it("should encode raw_transformation with %20", () => {
812+
const transformation = "l_text:Times New Roman_109_line_spacing_1:Heading,x_197,y_202";
813+
let url = cloudinary.utils.url("sample",
814+
{
815+
raw_transformation: transformation
816+
});
817+
expect(url).to.eql(`http://res.cloudinary.com/${cloud_name}/image/upload/l_text:Times%20New%20Roman_109_line_spacing_1:Heading,x_197,y_202/sample`);
818+
});
800819
});
801820
describe("streaming_profile", function () {
802821
it('should support streaming_profile in options', function () {

0 commit comments

Comments
 (0)