Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): validate no // in path when constructing payload url (#1…
Browse files Browse the repository at this point in the history
…9085)
  • Loading branch information
danielroe committed Feb 16, 2023
1 parent c45b842 commit 7aa35ff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/nuxt/src/app/composables/payload.ts
@@ -1,4 +1,4 @@
import { joinURL } from 'ufo'
import { joinURL, hasProtocol } from 'ufo'
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
import { useHead } from './head'

Expand Down Expand Up @@ -37,13 +37,13 @@ export function preloadPayload (url: string, opts: LoadPayloadOptions = {}) {
// --- Internal ---

function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) {
if (hasProtocol(url, true)) {
throw new Error('Payload URL must not include hostname: ' + url)
}
const u = new URL(url, 'http://localhost')
if (u.search) {
throw new Error('Payload URL cannot contain search params: ' + url)
}
if (u.host !== 'localhost') {
throw new Error('Payload URL cannot contain host: ' + url)
}
const hash = opts.hash || (opts.fresh ? Date.now() : '')
return joinURL(useRuntimeConfig().app.baseURL, u.pathname, hash ? `_payload.${hash}.js` : '_payload.js')
}
Expand Down

0 comments on commit 7aa35ff

Please sign in to comment.