-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve invalid link for
profile
(#421)
- Loading branch information
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function generateValidLink(url, username = '') { | ||
let validLink = url | ||
const validRegex = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/ | ||
|
||
if (!validLink.startsWith("http")) validLink = `http://${url}/` | ||
if (!validLink.match(validRegex)) validLink = `https://github.com/${username}/` | ||
|
||
return validLink | ||
} | ||
|
||
module.exports = { | ||
generateValidLink | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { generateValidLink } = require('../../lib/modules/helpers'); | ||
|
||
describe('generateValidLink', () => { | ||
const username = 'tenshiAMD' | ||
|
||
test('return valid link - no protocol', async () => { | ||
let url = 'tenshiamd.com'; | ||
let validUrl = generateValidLink(url, username); | ||
|
||
expect(validUrl).toEqual(`http://${url}/`); | ||
}); | ||
|
||
test('return valid link - incomplete URL format', async () => { | ||
let url = 'contributor'; | ||
let validUrl = generateValidLink(url, username); | ||
|
||
expect(validUrl).toEqual(`https://github.com/${username}/`); | ||
}); | ||
}); |
a82aa37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
app – ./
all-contributors.vercel.app
app-git-master-all-contributors.vercel.app
app-all-contributors.vercel.app
all-contributors-app.vercel.app