Skip to content

Commit

Permalink
Do not display social links in the tip dialog that have invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
zenparsing committed Oct 22, 2020
1 parent cca2dba commit b51effb
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 b51effb

Please sign in to comment.