From c1be6300adfa789fbb1bbf4c089ed434ff9deb02 Mon Sep 17 00:00:00 2001 From: Daniel Seripap Date: Mon, 27 Feb 2017 13:51:10 -0500 Subject: [PATCH] Strip names on creation as well --- src/app.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/app.js b/src/app.js index 4822de2..8305502 100644 --- a/src/app.js +++ b/src/app.js @@ -37,18 +37,19 @@ function generateNewRoom(req, res, id) { return res.redirect(`/${id}`); } -app.get('/', (req, res) => generateNewRoom(req, res, shortid.generate())); +function stripName(name) { + const chatName = name.toLowerCase().replace(/[^A-Za-z0-9]/g, '-'); + if (chatName.length >= 50) { + return chatName.substr(0, 50); + } + + return chatName; +}; + + +app.get('/', (req, res) => generateNewRoom(req, res, stripName(shortid.generate()))); app.get('/:roomId', (req, res) => { - const stripName = (name) => { - const chatName = name.toLowerCase().replace(/[^A-Za-z0-9]/g, '-'); - if (chatName.length >= 50) { - return chatName.substr(0, 50); - } - - return chatName; - }; - const roomId = stripName(req.params.roomId) || false; let roomExists = _.findWhere(rooms, {_id: roomId}) || false;