fix regex accepting possible incorrect names, also make case insensitive

jschan
Thomas Lynch 3 years ago
parent 3cf216450e
commit 9edbac671a
  1. 2
      controllers/forms/addcustompage.js
  2. 2
      controllers/forms/editcustompage.js
  3. 2
      views/pages/editcustompage.pug
  4. 2
      views/pages/managecustompages.pug

@ -25,7 +25,7 @@ module.exports = {
{ result: existsBody(req.body.page), expected: true, error: 'Missing .html name' }, { result: existsBody(req.body.page), expected: true, error: 'Missing .html name' },
{ result: () => { { result: () => {
if (req.body.page) { if (req.body.page) {
return /[a-z0-9_-]+/.test(req.body.page); return /^[a-z0-9_-]+$/i.test(req.body.page);
} }
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' },

@ -27,7 +27,7 @@ module.exports = {
{ result: existsBody(req.body.page), expected: true, error: 'Missing .html name' }, { result: existsBody(req.body.page), expected: true, error: 'Missing .html name' },
{ result: () => { { result: () => {
if (req.body.page) { if (req.body.page) {
return /[a-z0-9_-]+/.test(req.body.page); return /^[a-z0-9_-]+$/i.test(req.body.page);
} }
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' },

@ -12,7 +12,7 @@ block content
input(type='hidden' name='page_id' value=page._id) input(type='hidden' name='page_id' value=page._id)
.row .row
.label .html name .label .html name
input(type='text' name='page' pattern='[a-z0-9-_]+' title='a-z0-9-_ only' value=page.page required) input(type='text' name='page' pattern='[a-zA-Z0-9-_]+' title='a-zA-Z0-9-_ only' value=page.page required)
.table-container.flex-center.mv-5 .table-container.flex-center.mv-5
table table
tr tr

@ -17,7 +17,7 @@ block content
input(type='hidden' name='_csrf' value=csrf) input(type='hidden' name='_csrf' value=csrf)
.row .row
.label .html name .label .html name
input(type='text' name='page' pattern='[a-z0-9-_]+' title='a-z0-9-_ only' required) input(type='text' name='page' pattern='[a-zA-Z0-9-_]+' title='a-zA-Z0-9-_ only' required)
.row .row
.label Title .label Title
input(type='text' name='title' required) input(type='text' name='title' required)

Loading…
Cancel
Save