Skip to content

Commit 5f0693a

Browse files
committed
fix(nuxt): use URL constructor to resolve external protocols
1 parent 8e793ad commit 5f0693a

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/nuxt/src/app/composables/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
140140
if (!options?.external) {
141141
throw new Error('Navigating to an external URL is not allowed by default. Use `navigateTo(url, { external: true })`.')
142142
}
143-
const protocol = parseURL(toPath).protocol
143+
const { protocol } = new URL(toPath)
144144
if (protocol && isScriptProtocol(protocol)) {
145145
throw new Error(`Cannot navigate to a URL with '${protocol}' protocol.`)
146146
}

packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ref } from 'vue'
2-
import { parseURL } from 'ufo'
32
import { useHead } from '@unhead/vue'
43
import { defineNuxtPlugin } from '../nuxt'
54

5+
const SUPPORTED_PROTOCOLS = ['http:', 'https:']
6+
67
export default defineNuxtPlugin({
78
name: 'nuxt:cross-origin-prefetch',
89
setup (nuxtApp) {
@@ -26,8 +27,7 @@ export default defineNuxtPlugin({
2627
script: [generateRules()],
2728
})
2829
nuxtApp.hook('link:prefetch', (url) => {
29-
const { protocol } = parseURL(url)
30-
if (protocol && ['http:', 'https:'].includes(protocol)) {
30+
if (SUPPORTED_PROTOCOLS.some(p => url.startsWith(p)) && SUPPORTED_PROTOCOLS.includes(new URL(url).protocol)) {
3131
externalURLs.value.add(url)
3232
head?.patch({
3333
script: [generateRules()],

0 commit comments

Comments
 (0)