Explicitly validate slashes presence

master
Sven Slootweg 4 years ago
parent 84ce0dd86a
commit 8fdab33e8b

@ -10,9 +10,14 @@ console.log(validateValue("bar", [ isURL() ])); /*
- At (root): Must be a valid URL
*/
console.log(validateValue("https://example.com/", [ isURL([ "http", "https" ]) ])); // Url { ... }
console.log(validateValue("https://example.com/", [ isURL([ "http://", "https://" ]) ])); // Url { ... }
console.log(validateValue("ftp://example.com/", [ isURL([ "http", "https" ]) ])); /*
console.log(validateValue("https:example.com/", [ isURL([ "http://", "https://" ]) ])); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Must be a URL with one of the following protocols: HTTP, HTTPS - but got FTP instead
- At (root): Must be a URL with one of the following protocols: HTTP://, HTTPS:// - but got HTTPS: instead
*/
console.log(validateValue("ftp://example.com/", [ isURL([ "http://", "https://" ]) ])); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Must be a URL with one of the following protocols: HTTP://, HTTPS:// - but got FTP:// instead
*/

@ -18,8 +18,12 @@ module.exports = function (protocols) {
function isURL(value) {
let parsed = url.parse(value);
let slashes = (parsed.slashes === true)
? "//"
: "";
let parsedProtocol = (parsed.protocol != null)
? parsed.protocol.replace(/:$/, "")
? parsed.protocol + slashes
: null;
if (parsedProtocol == null) {

Loading…
Cancel
Save