Skip to content

Commit

Permalink
Merge pull request #6918 from brave/ksmith-tip-dialog-bad-links
Browse files Browse the repository at this point in the history
Do not display social links in the tip dialog that have invalid URLs
  • Loading branch information
zenparsing authored Oct 22, 2020
2 parents 6e4d625 + b51effb commit 62385fc
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,23 @@ function getSocialIcon (type: string) {
}
}

function isValidSocialLink (url: string) {
try {
// The URL constructor will throw when provided with any
// string that is not an absolute URL. If the URL constuctor
// does not throw, consider it a valid social link URL.
// tslint:disable-next-line:no-unused-expression
new URL(url)
return true
} catch (_) {
return false
}
}

function getSocialLinks (publisherInfo: PublisherInfo) {
return Object.entries(publisherInfo.links).map(([type, url]) => {
const icon = getSocialIcon(type)
return icon
return icon && isValidSocialLink(url)
? <NewTabLink key={type} href={url}>{icon}</NewTabLink>
: null
})
Expand Down

0 comments on commit 62385fc

Please sign in to comment.