Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const down = function (resource) {
if (!validator.isURL(resource.origin)) {
logger.error('Unable to download %s. Bad URL.', resource.origin)
return Promise.resolve('Bad URL: ' + resource.origin)
}
logger.debug('Downloading %s to container %s...', resource.origin, container)
const tryDownload = function () {
return storage.store(container, resource.key, request(resource.origin), {'Content-Type': resource.type})
}
const hostname = url.parse(resource.origin).hostname
return nodefn.call(dns.resolve4, hostname)
.then(tryDownload, function (/* e */) {
logger.error('Unable to download %s. Host cannot be resolved: %s', resource.origin, hostname)
return Promise.reject(`Host cannot be resolved: ${hostname}`)
})
}
website(model) {
let website = model.get('website');
// eslint-disable-next-line camelcase
let isInvalidWebsite = !validator.isURL(website || '', {require_protocol: false})
|| !validator.isLength(website || '', 0, 2000);
if (this.isActive(model)) {
if (!isBlank(website) && isInvalidWebsite) {
model.get('errors').add('website', 'Website is not a valid url');
this.invalidate();
}
}
},
exports.isUrl = (site = '') => {
if (!site) return true
return validator.isURL(site, {
protocols: ['http', 'https'],
require_protocol: true
})
}
const { type, required } = this.props;
if ( value.length === 0 ) {
return ! required;
}
let isValid = true;
switch ( type ) {
case 'tel':
isValid = validator.isMobilePhone( value, 'any' );
break;
case 'email':
isValid = validator.isEmail( value );
break;
case 'url':
isValid = validator.isURL( value );
break;
case 'number':
isValid = validator.isNumeric( value );
break;
}
return isValid;
}
getContents(file, callback) {
var contents;
var isUrl = validator.isURL(file);
if (isUrl) {
http.get(file, (response) => {
response.setEncoding('utf8');
response.on('data', (data) => {
callback(data);
});
});
} else {
fs.readFile(file, 'utf8', (err, data) => {
callback(data.toString());
});
}
if (!validator.isHexColor(text)) {
is_valid = false;
}
break;
case "identity-card":
if (!validator.isIdentityCard(text, this.getLocale())) {
is_valid = false;
}
break;
case "credit-card":
if (!validator.isCreditCard(text)) {
is_valid = false;
}
break;
case "url":
if (!validator.isURL(text)) {
is_valid = false;
}
break;
case "numeric":
if (!this.isNumeric(text) && !validator.isNumeric(text)) {
is_valid = false;
}
break;
case "integer":
case "int":
if (!this.isNumeric(text) && !validator.isNumeric(text)) {
is_valid = false;
}
break;
case "real":
case "float":
function _isValidUrl(url) {
return url && typeof url === "string" && validator.isURL(url);
}
validate: function (url) {
return (url).length ? (validator.isURL(url) || 'The project author\'s website must be a valid URL or empty!') : true;
}
}];
router.post('/me/user_info', function(req,res,next){
if (!req.user){
var error = new Error("You must be logged in to access this resource.");
error.status = 403;
return next(error);
}
var avatar = req.body.avatar;
var bio = req.body.bio;
var imgurMatch = /(https?:\/\/)?(www\.)?(i\.)?imgur\.com\/(gallery\/)?([a-zA-Z0-9]+)(\.(jpg|jpeg|png|gif))?/i;
if (avatar != undefined){
if (!validator.isURL(avatar,{host_whitelist:["i.imgur.com","www.imgur.com","imgur.com"]})){
var error = new Error("Only IMGUR URLs are allowed.");
error.status = 422;
error.field_name = "avatar";
error.type = "validation";
return next(error);
}
avatar = avatar.replace(imgurMatch,"$5");
}
queries.updateUser(req.user.user_id,avatar,bio).then(function(){
return queries.getUser(req.user.username);
}).then(function(user){
res.json(user);
}).catch(function(err){
next(err);
});
});
validate.url = function (input) {
var error = 'Please enter a valid url';
return validator.isURL(input) ? true : error;
};