Skip to content

Commit

Permalink
Fixed isRemoteUrl to correctly detect docx files
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-tolosa authored and strausr committed Jan 19, 2020
1 parent 728b85d commit 5c4504a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib-es5/utils/isRemoteUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var isString = require('lodash/isString');
* @returns {boolean} true if the given url is a remote location or data
*/
function isRemoteUrl(url) {
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-]+\/[\w-]+)?(;[\w-]+=[\w-]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(url);
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(url);
}

module.exports = isRemoteUrl;
2 changes: 1 addition & 1 deletion lib/utils/isRemoteUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const isString = require('lodash/isString');
* @returns {boolean} true if the given url is a remote location or data
*/
function isRemoteUrl(url) {
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-]+\/[\w-]+)?(;[\w-]+=[\w-]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(url);
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(url);
}

module.exports = isRemoteUrl;
10 changes: 10 additions & 0 deletions test/uploader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ describe("uploader", function () {
expect(result.signature).to.eql(expected_signature);
});
});

it("Should upload a valid docx file as base64", function () {
let data = 'data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,UEsDBBQACAgIAI02LlAAAAAAAAAAAAAAAAASAAAAd29yZ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ADiEQAADwAAAAAAAAAAAAAAAAClBQAAd29yZC9zdHlsZXMueG1sUEsBAhQAFAAICAgAjTYuUMFLkk43AgAAQQcAABEAAAAAAAAAAAAAAAAABAkAAHdvcmQvZG9jdW1lbnQueG1sUEsBAhQAFAAICAgAjTYuUJAAq+vxAAAALAMAABwAAAAAAAAAAAAAAAAAegsAAHdvcmQvX3JlbHMvZG9jdW1lbnQueG1sLnJlbHNQSwECFAAUAAgICACNNi5QLWjPIrEAAAAqAQAACwAAAAAAAAAAAAAAAAC1DAAAX3JlbHMvLnJlbHNQSwECFAAUAAgICACNNi5QIVqihCwGAADbHQAAFQAAAAAAAAAAAAAAAACfDQAAd29yZC90aGVtZS90aGVtZTEueG1sUEsBAhQAFAAICAgAjTYuUDOvD7csAQAALQQAABMAAAAAAAAAAAAAAAAADhQAAFtDb250ZW50X1R5cGVzXS54bWxQSwUGAAAAAAkACQBCAgAAexUAAAAA';

return cloudinary.v2.uploader.upload(data, {
resource_type: 'auto', // this defaults to 'image' if not specified
tags: UPLOAD_TAGS,
});
});

describe("remote urls ", function () {
var writeSpy;
writeSpy = void 0;
Expand Down
1 change: 1 addition & 0 deletions test/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@ describe("utils", function () {
"s3://s3-us-west-2.amazonaws.com/cloudinary/images/old_logo.png",
"gs://cloudinary/images/old_logo.png",
"data:image/gif;charset=utf8;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
"data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
"data:image/gif;param1=value1;param2=value2;base64,"
+ "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
cloudinary.BLANK,
Expand Down

0 comments on commit 5c4504a

Please sign in to comment.