Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isFile(source) || isDirectory(source)) {
target = new URL(fileUrl(source));
debug(`Adding valid target: ${url.format(target)}`);
return target;
}
target = new URL(`http://${source}`);
/*
* And it doesn't exist locally, and is a valid URL:
* Except for the case of the well known and used `localhost`,
* for all other cases the `hostname` needs to contain at least
* a `.`. Private domains should have `http(s)://` in front.
*/
if (!pathExists(source) && (target.hostname === 'localhost' || target.hostname.includes('.'))) {
debug(`Adding modified target: ${url.format(target)}`);
return target;
}
// If it's not a regular file or looks like a URL, ignore it.
logger.error(`Ignoring '${source}' as it's not an existing file nor a valid URL`);
return null;
};