Skip to content

Commit

Permalink
fix(app-vite): filter env files keys (a-zA-Z0-9 chars only) #17744
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Jan 13, 2025
1 parent 5c28604 commit a79c920
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions app-vite/lib/utils/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export function readFileEnv ({ ctx, quasarConf }) {
const cache = cacheProxy.getRuntime(readFileEnvCacheKey, () => ({}))

if (cache.configHash !== configHash) {
const result = getFileEnvResult(ctx.appPaths, {
const result = getFileEnvResult({
...opts,
appPaths: ctx.appPaths,
quasarMode: ctx.modeName,
buildType: ctx.dev ? 'dev' : 'prod'
})
Expand All @@ -48,15 +49,13 @@ export function readFileEnv ({ ctx, quasarConf }) {
return cache.result
}

function getFileEnvResult (
function getFileEnvResult ({
appPaths,
{
quasarMode,
buildType,
envFolder = appPaths.appDir,
envFiles = []
}
) {
quasarMode,
buildType,
envFolder = appPaths.appDir,
envFiles = []
}) {
const fileList = [
// .env
// loaded in all cases
Expand Down Expand Up @@ -120,15 +119,25 @@ function getFileEnvResult (
return {}
}

const { parsed: fileEnv } = dotEnvExpand({ parsed: env })
const rawFileEnv = {}
dotEnvExpand({ processEnv: rawFileEnv, parsed: env })

return {
fileEnv,
fileEnv: getFileEnv(rawFileEnv),
usedEnvFiles,
envFromCache: false
}
}

const validKeyRE = /^[a-zA-Z][a-zA-Z0-9_]+/
function getFileEnv (env) {
const validKeys = Object.keys(env).filter(key => validKeyRE.test(key))
return validKeys.reduce((acc, key) => {
acc[ key ] = env[ key ]
return acc
}, {})
}

/**
* Get the final env definitions to supply to
* the build system (Vite or Esbuild).
Expand Down

0 comments on commit a79c920

Please sign in to comment.