Skip to content

Commit

Permalink
fix: isRemoteUrl check improved to reduce false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudinary-pkoniu committed May 2, 2023
1 parent f57b1ed commit aaaf45f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
* fix: smd number field allows both numbers and string when uploading
* fix: isRemoteUrl not working on big files sometimes


/ 2023-05-02
=============

* Merge pull request #584 from matheuswanted/fix/isRemoteUrl-breaking
* Merge pull request #603 from cloudinary/smd-number-field-fix
* fix: smd number field allows both numbers and string when uploading
* fix: isRemoteUrl not working on big files sometimes
1.36.2 / 2023-04-24
==================

Expand Down
4 changes: 3 additions & 1 deletion lib/utils/isRemoteUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ 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:/.test(url);
const SUBSTRING_LENGTH = 120;
const urlSubstring = url.substring(0, SUBSTRING_LENGTH);
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+(\+[\w-.]+)?)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(urlSubstring);
}

module.exports = isRemoteUrl;

0 comments on commit aaaf45f

Please sign in to comment.