Skip to content

Commit 5bc9323

Browse files
Merge pull request #605 from cloudinary/fix-is-remote-url-test-regex-on-substring
fix: isRemoteUrl check improved to reduce false positives
2 parents f57b1ed + f839798 commit 5bc9323

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib-es5/utils/isRemoteUrl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ var isString = require('lodash/isString');
88
* @returns {boolean} true if the given url is a remote location or data
99
*/
1010
function isRemoteUrl(url) {
11-
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:/.test(url);
11+
var SUBSTRING_LENGTH = 120;
12+
var urlSubstring = isString(url) && url.substring(0, SUBSTRING_LENGTH);
13+
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+(\+[\w-.]+)?)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(urlSubstring);
1214
}
1315

1416
module.exports = isRemoteUrl;

lib/utils/isRemoteUrl.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const isString = require('lodash/isString');
66
* @returns {boolean} true if the given url is a remote location or data
77
*/
88
function isRemoteUrl(url) {
9-
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:/.test(url);
9+
const SUBSTRING_LENGTH = 120;
10+
const urlSubstring = isString(url) && url.substring(0, SUBSTRING_LENGTH);
11+
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+(\+[\w-.]+)?)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(urlSubstring);
1012
}
1113

1214
module.exports = isRemoteUrl;

0 commit comments

Comments
 (0)