From 395403d18a18810d8500addcaefcbc6ff277f795 Mon Sep 17 00:00:00 2001 From: Yash Kumar Verma Date: Sat, 30 May 2020 22:20:33 +0530 Subject: [PATCH] Ensure new claims have clean urls, Fixes: #390 --- routes/api.js | 4 ++-- routes/root.js | 4 ++-- utils/datautils.js | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/routes/api.js b/routes/api.js index 6e0ddbb..8d86241 100644 --- a/routes/api.js +++ b/routes/api.js @@ -69,8 +69,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => { du.createClaim( req.user.usergithub.username, - req.body.issue_url, - req.body.pull_url, + du.generateGenericUrl(req.body.issue_url), + du.generateGenericUrl(req.body.pull_url), req.body.bounty, config.CLAIM_STATUS.CLAIMED ) diff --git a/routes/root.js b/routes/root.js index a4b548d..a751701 100644 --- a/routes/root.js +++ b/routes/root.js @@ -248,8 +248,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => { du.createClaim( req.user.usergithub.username, // github username already valid - req.body.issue_url, - req.body.pull_url, + du.generateGenericUrl(req.body.issue_url), + du.generateGenericUrl(req.body.pull_url), req.body.bounty, config.CLAIM_STATUS.CLAIMED ) diff --git a/utils/datautils.js b/utils/datautils.js index 0efa24c..ff0a21d 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -5,6 +5,12 @@ const db = require('./db') const fs = require('fs') const consts = require('./consts') +function generateGenericUrl(url) { + const extractSingleUrl = url.trim().split(' ')[0].split('#')[0] + const genericUrl = new URL(extractSingleUrl).pathname.replace(/\/+$/, '') + return `https://github.com${genericUrl}` +} + function getContestPeriod(year) { if (year) return { @@ -180,5 +186,6 @@ module.exports = { getLoggedInUserStats, getClaimById, updateClaim, + generateGenericUrl, getCounts }