Implemented ESlint and passed down the rules

This commit is contained in:
Alexis
2021-01-20 19:07:56 +01:00
parent 615cced6ed
commit b318a88023
37 changed files with 2119 additions and 568 deletions

View File

@@ -1,35 +1,35 @@
const regexInt = RegExp(/^[1-9]\d*$/)
const regexXSS = RegExp(/<[^>]*script/)
const regexInt = RegExp(/^[1-9]\d*$/);
const regexXSS = RegExp(/<[^>]*script/);
// Check if int for param validation
const paramIntCheck = (req, res, next, input) => {
try {
if (regexInt.test(input)) {
next()
next();
} else {
throw new Error
throw new Error;
}
} catch (err) {
res.status(err.code).send(JSON.stringify({
"message": "Le paramètre doit être un entier non-nul.",
"code": 403,
})
)
);
}
}
};
// Check if script injection attempt
const isXSSAttempt = (string) => {
return regexXSS.test(string);
}
};
// Check if object is null
const isEmptyObject = (obj) => {
return (Object.keys(obj).length === 0 && obj.constructor === Object);
}
};
module.exports = {
paramIntCheck,
isXSSAttempt,
isEmptyObject
}
};