From aaaf45f56522b4b4dea03dfc84e748784ee36714 Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 2 May 2023 12:16:16 +0200 Subject: [PATCH 1/5] fix: isRemoteUrl check improved to reduce false positives --- CHANGELOG.md | 8 ++++++++ lib/utils/isRemoteUrl.js | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d19a88b6..0bbc057b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ================== diff --git a/lib/utils/isRemoteUrl.js b/lib/utils/isRemoteUrl.js index e1f77cc3..a131b24e 100644 --- a/lib/utils/isRemoteUrl.js +++ b/lib/utils/isRemoteUrl.js @@ -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; From 19ebc8413bb747eb24f6a14b210713ae3cca5ee3 Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 2 May 2023 12:18:15 +0200 Subject: [PATCH 2/5] fix: isRemoteUrl check improved to reduce false positives --- lib-es5/utils/isRemoteUrl.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib-es5/utils/isRemoteUrl.js b/lib-es5/utils/isRemoteUrl.js index 0388feae..07fd4d89 100644 --- a/lib-es5/utils/isRemoteUrl.js +++ b/lib-es5/utils/isRemoteUrl.js @@ -8,7 +8,9 @@ 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:/.test(url); + var SUBSTRING_LENGTH = 120; + var 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; \ No newline at end of file From d862be83e56ceb882bd3e9aba29428a82540779b Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 2 May 2023 12:18:53 +0200 Subject: [PATCH 3/5] chore: removed manual changelog entries --- CHANGELOG.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bbc057b..d19a88b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,6 @@ * 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 ================== From b9d82665c99a409f60928ba4e454bbcabf989c6d Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 2 May 2023 13:34:51 +0200 Subject: [PATCH 4/5] fix: taking substring only if input is a string --- lib/utils/isRemoteUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/isRemoteUrl.js b/lib/utils/isRemoteUrl.js index a131b24e..eadcce77 100644 --- a/lib/utils/isRemoteUrl.js +++ b/lib/utils/isRemoteUrl.js @@ -7,7 +7,7 @@ const isString = require('lodash/isString'); */ function isRemoteUrl(url) { const SUBSTRING_LENGTH = 120; - const urlSubstring = url.substring(0, SUBSTRING_LENGTH); + const urlSubstring = isString(url) && 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); } From f8397989240203110acb3cdabef9d7e2c2ef5b0d Mon Sep 17 00:00:00 2001 From: cloudinary-pkoniu Date: Tue, 2 May 2023 13:46:04 +0200 Subject: [PATCH 5/5] fix: taking substring only if input is a string --- lib-es5/utils/isRemoteUrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib-es5/utils/isRemoteUrl.js b/lib-es5/utils/isRemoteUrl.js index 07fd4d89..7f2faff8 100644 --- a/lib-es5/utils/isRemoteUrl.js +++ b/lib-es5/utils/isRemoteUrl.js @@ -9,7 +9,7 @@ var isString = require('lodash/isString'); */ function isRemoteUrl(url) { var SUBSTRING_LENGTH = 120; - var urlSubstring = url.substring(0, SUBSTRING_LENGTH); + var urlSubstring = isString(url) && 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); }