mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
fix(nuxt): validate no //
in path when constructing payload url (#19085)
This commit is contained in:
parent
c45b842037
commit
7aa35ff958
@ -1,4 +1,4 @@
|
||||
import { joinURL } from 'ufo'
|
||||
import { joinURL, hasProtocol } from 'ufo'
|
||||
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||
import { useHead } from './head'
|
||||
|
||||
@ -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')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user