From eb3d97be7db1d282e969787092846769279bb499 Mon Sep 17 00:00:00 2001 From: Wingysam Date: Thu, 22 Nov 2018 16:59:21 -0500 Subject: [PATCH] Only check after last space for url --- routes/wishlist/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index 7ec7ea7..c481df0 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -41,18 +41,19 @@ module.exports = (db) => { }); router.post('/:user', verifyAuth(), async (req, res) => { - const isUrl = ValidURL(req.body.itemUrlOrName); + const potentialUrl = req.body.itemUrlOrName.split(' ').pop(); + const isUrl = ValidURL(potentialUrl); const item = {}; let productData; try { - if (isUrl) productData = await getProductName(req.body.itemUrlOrName, config.proxyServer); + if (isUrl) productData = await getProductName(potentialUrl, config.proxyServer); } catch (err) { req.flash('error', err.toString()); } item.name = (productData ? productData.name : req.body.itemUrlOrName); item.addedBy = req.user._id; item.pledgedBy = (req.user._id === req.params.user ? undefined : req.user._id); - if (isUrl) item.url = req.body.itemUrlOrName; + if (isUrl) item.url = potentialUrl; item.id = uuid(); const doc = await db.get(req.params.user); doc.wishlist.push(item);