Skip to content

Commit

Permalink
Ensure new claims have clean urls, Fixes: #390
Browse files Browse the repository at this point in the history
  • Loading branch information
YashKumarVerma committed May 30, 2020
1 parent e630916 commit 395403d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
7 changes: 7 additions & 0 deletions utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -180,5 +186,6 @@ module.exports = {
getLoggedInUserStats,
getClaimById,
updateClaim,
generateGenericUrl,
getCounts
}

0 comments on commit 395403d

Please sign in to comment.