Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,16 @@ describe('resolveEnvPrefix', () => {
expect(() => resolveEnvPrefix(config)).toThrow()
})

test(`throw error if envPrefix contains whitespace`, () => {
let config: UserConfig = { envPrefix: 'WITH SPACE' }
expect(() => resolveEnvPrefix(config)).toThrow()
config = { envPrefix: ['CUSTOM_', 'ANOTHER SPACE'] }
expect(() => resolveEnvPrefix(config)).toThrow()
})

test('should work correctly for valid envPrefix value', () => {
const config: UserConfig = { envPrefix: [' ', 'CUSTOM_'] }
expect(resolveEnvPrefix(config)).toMatchObject([' ', 'CUSTOM_'])
const config: UserConfig = { envPrefix: ['CUSTOM_'] }
expect(resolveEnvPrefix(config)).toMatchObject(['CUSTOM_'])
})
})

Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,10 @@ export function resolveEnvPrefix({
`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`,
)
}
if (envPrefix.some((prefix) => prefix.includes(' '))) {
Comment thread
bluwy marked this conversation as resolved.
Outdated
throw new Error(
`envPrefix option contains values with whitespace, which could lead to unexpected behavior.`,
)
}
return envPrefix
}