mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
fix(config): avoid recursion when interpolating env (#8014)
This commit is contained in:
parent
a3d836401c
commit
4de44e6c52
@ -153,7 +153,7 @@ function expand (target, source = {}, parse = v => v) {
|
|||||||
return source[key] !== undefined ? source[key] : target[key]
|
return source[key] !== undefined ? source[key] : target[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
function interpolate (value) {
|
function interpolate (value, parents = []) {
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
@ -171,10 +171,16 @@ function expand (target, source = {}, parse = v => v) {
|
|||||||
const key = parts[2]
|
const key = parts[2]
|
||||||
replacePart = parts[0].substring(prefix.length)
|
replacePart = parts[0].substring(prefix.length)
|
||||||
|
|
||||||
|
// Avoid recursion
|
||||||
|
if (parents.includes(key)) {
|
||||||
|
consola.warn(`Please avoid recursive environment variables ( loop: ${parents.join(' > ')} > ${key} )`)
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
value = getValue(key)
|
value = getValue(key)
|
||||||
|
|
||||||
// Resolve recursive interpolations
|
// Resolve recursive interpolations
|
||||||
value = interpolate(value)
|
value = interpolate(value, [...parents, key])
|
||||||
}
|
}
|
||||||
|
|
||||||
return value !== undefined ? newValue.replace(replacePart, value) : newValue
|
return value !== undefined ? newValue.replace(replacePart, value) : newValue
|
||||||
|
3
test/fixtures/runtime-config/.env
vendored
3
test/fixtures/runtime-config/.env
vendored
@ -2,4 +2,7 @@ BASE_URL=/api
|
|||||||
PUBLIC_URL=https://google.com
|
PUBLIC_URL=https://google.com
|
||||||
SERVER_BASE_URL
|
SERVER_BASE_URL
|
||||||
API_SECRET=1234
|
API_SECRET=1234
|
||||||
|
A=$B
|
||||||
|
B=$C
|
||||||
|
C=$A
|
||||||
TOKEN=$2yr$10$tN3JmuvXZKGwi0l38A.SxUVemGrFJiyLunyqkOqOTE7LHsrSwMEmEB
|
TOKEN=$2yr$10$tN3JmuvXZKGwi0l38A.SxUVemGrFJiyLunyqkOqOTE7LHsrSwMEmEB
|
||||||
|
3
test/fixtures/runtime-config/nuxt.config.js
vendored
3
test/fixtures/runtime-config/nuxt.config.js
vendored
@ -6,7 +6,8 @@ export default {
|
|||||||
},
|
},
|
||||||
privateRuntimeConfig: {
|
privateRuntimeConfig: {
|
||||||
baseURL: '${PUBLIC_URL}${BASE_URL}',
|
baseURL: '${PUBLIC_URL}${BASE_URL}',
|
||||||
API_SECRET: ''
|
API_SECRET: '',
|
||||||
|
FOO: '123/${FOO}'
|
||||||
},
|
},
|
||||||
serverMiddleware: [
|
serverMiddleware: [
|
||||||
(req, _, next) => {
|
(req, _, next) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user