Coerce values to string before using validator methods
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { isAlphanumeric, isHexadecimal } from 'validator';
|
import { isAlphanumeric, isMongoId } from 'validator';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
|
||||||
const log = debug('fcc:models:promo');
|
const log = debug('fcc:models:promo');
|
||||||
@ -6,16 +6,16 @@ const log = debug('fcc:models:promo');
|
|||||||
export default function promo(Promo) {
|
export default function promo(Promo) {
|
||||||
Promo.getButton = function getButton(id, code, type = 'isNot') {
|
Promo.getButton = function getButton(id, code, type = 'isNot') {
|
||||||
const Job = Promo.app.models.Job;
|
const Job = Promo.app.models.Job;
|
||||||
if (!id || !isHexadecimal(id)) {
|
if (!id || !isMongoId('' + id)) {
|
||||||
return Promise.reject(new Error(
|
return Promise.reject(new Error(
|
||||||
'Must include job id'
|
'Must include job id'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isAlphanumeric(code) &&
|
!isAlphanumeric('' + code) &&
|
||||||
type &&
|
type &&
|
||||||
!isAlphanumeric(type)
|
!isAlphanumeric('' + type)
|
||||||
) {
|
) {
|
||||||
return Promise.reject(new Error(
|
return Promise.reject(new Error(
|
||||||
'Code or Type should be an alphanumeric'
|
'Code or Type should be an alphanumeric'
|
||||||
|
@ -431,7 +431,7 @@ module.exports = function(app) {
|
|||||||
challengeId = badIdMap[challengeId];
|
challengeId = badIdMap[challengeId];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMongoId(challengeId)) {
|
if (!isMongoId('' + challengeId)) {
|
||||||
challengeId = null;
|
challengeId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ module.exports = function(app) {
|
|||||||
challengeId = badIdMap[challengeId];
|
challengeId = badIdMap[challengeId];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isMongoId(challengeId)) {
|
if (!isMongoId('' + challengeId)) {
|
||||||
challengeId = null;
|
challengeId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
var url = req.body.data.url;
|
var url = req.body.data.url;
|
||||||
|
|
||||||
if (!validator.isURL(url)) {
|
if (!validator.isURL('' + url)) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "The URL you submitted doesn't appear valid"
|
msg: "The URL you submitted doesn't appear valid"
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user