fix: fix malformed URLs in statuses (#1385)

fixes #1384
This commit is contained in:
Nolan Lawson 2019-08-11 11:09:51 -07:00 committed by GitHub
parent c5e2eeee2d
commit ea58242b85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -87,6 +87,7 @@
import { store } from '../../_store/store'
import { classname } from '../../_utils/classname'
import { massageUserText } from '../../_utils/massageUserText'
import { urlIsCrossOrigin } from '../../_utils/urlIsCrossOrigin'
export default {
oncreate () {
@ -141,7 +142,7 @@
}
// hydrate external links
const href = anchor.getAttribute('href')
if (new URL(href, location.href).origin !== location.origin) {
if (urlIsCrossOrigin(href)) {
anchor.setAttribute('title', href)
anchor.setAttribute('target', '_blank')
anchor.setAttribute('rel', 'nofollow noopener')

View file

@ -0,0 +1,8 @@
export function urlIsCrossOrigin (href) {
try {
return new URL(href, location.href).origin !== location.origin
} catch (e) {
console.error('Ignoring malformed URL', href)
return true
}
}