fixes to paramconverter, null 0 length trimmed fields, tweak custompage error

indiachan-spamvector
Thomas Lynch 3 years ago
parent 63d74631ae
commit 5e4c1b197f
  1. 2
      controllers/forms/addcustompage.js
  2. 5
      helpers/paramconverter.js

@ -29,7 +29,7 @@ module.exports = {
} }
return false; return false;
} , expected: true, error: '.html name must contain a-z 0-9 _ - only' }, } , expected: true, error: '.html name must contain a-z 0-9 _ - only' },
{ result: numberBody(res.locals.messageLength, 0, globalLimits.customPages.maxLength), expected: true, error: `Message must be ${globalLimits.customPages.maxLength} characters or less` }, { result: !existsBody(req.body.message) || numberBody(res.locals.messageLength, 0, globalLimits.customPages.maxLength), expected: true, error: `Message must be ${globalLimits.customPages.maxLength} characters or less` },
{ result: lengthBody(req.body.title, 0, 50), expected: false, error: 'Title must be 50 characters or less' }, { result: lengthBody(req.body.title, 0, 50), expected: false, error: 'Title must be 50 characters or less' },
{ result: lengthBody(req.body.page, 0, 50), expected: false, error: '.html name must be 50 characters or less' }, { result: lengthBody(req.body.page, 0, 50), expected: false, error: '.html name must be 50 characters or less' },
{ result: async () => { { result: async () => {

@ -29,6 +29,7 @@ module.exports = (options) => {
const { timeFields, trimFields, allowedArrays, const { timeFields, trimFields, allowedArrays,
processThreadIdParam, processDateParam, processMessageLength, processThreadIdParam, processDateParam, processMessageLength,
numberFields, numberArrays, objectIdFields, objectIdArrays } = options; numberFields, numberArrays, objectIdFields, objectIdArrays } = options;
/* check all body fields, body-parser prevents this array being too big, so no worry. /* check all body fields, body-parser prevents this array being too big, so no worry.
whitelist for fields that can be arrays, and convert singular of those fields to 1 length array */ whitelist for fields that can be arrays, and convert singular of those fields to 1 length array */
const bodyFields = Object.keys(req.body); const bodyFields = Object.keys(req.body);
@ -50,7 +51,7 @@ module.exports = (options) => {
const field = trimFields[i]; const field = trimFields[i];
if (req.body[field]) { if (req.body[field]) {
//trimEnd() because trailing whitespace doesnt affect how a post appear and if it is all whitespace, trimEnd will get it all anyway //trimEnd() because trailing whitespace doesnt affect how a post appear and if it is all whitespace, trimEnd will get it all anyway
req.body[field] = req.body[field].trimEnd(); req.body[field] = req.body[field].trimEnd() || null;
} }
} }
@ -143,7 +144,7 @@ module.exports = (options) => {
} }
/* normalise message length check for CRLF vs just LF, because String.length depending on browser wont count CRLF as /* normalise message length check for CRLF vs just LF, because String.length depending on browser wont count CRLF as
2 characters, so user gets "message too long" at the right length. */ 2 characters, so user gets "message too long" at the right length. Maybe will add another array for these in future */
if (processMessageLength && req.body.message) { if (processMessageLength && req.body.message) {
res.locals.messageLength = req.body.message.replace(/\r\n/igm, '\n').length; res.locals.messageLength = req.body.message.replace(/\r\n/igm, '\n').length;
} }

Loading…
Cancel
Save