1
0

fix: early return on invalid permalinks

resolves #255
This commit is contained in:
Daniel Roe 2022-11-30 13:31:33 +00:00
parent 71fbe6acf9
commit 24bbe9135b
No known key found for this signature in database
GPG Key ID: 22D5008E4F5D9B55

View File

@ -3,10 +3,15 @@ import { parseURL } from 'ufo'
definePageMeta({
middleware: async (to) => {
const HANDLED_MASTO_URL = /^(https?:\/\/)?(\w+\.)+\w+\/(@[@\w\d\.]+)(\/\d+)?$/
try {
let permalink = Array.isArray(to.params.permalink)
? to.params.permalink.join('/')
: to.params.permalink
if (!HANDLED_MASTO_URL.test(permalink))
return '/home'
if (!permalink.startsWith('http'))
permalink = `https://${permalink}`
@ -29,6 +34,8 @@ definePageMeta({
}
if (accounts[0])
return getAccountPath(accounts[0])
}
catch {}
return '/home'
},