Skip to content

Commit

Permalink
feat: restrict characters useable for environment name
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Oct 2, 2024
1 parent 78e749e commit 185352a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/node/baseEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export class PartialEnvironment {
topLevelConfig: ResolvedConfig,
options: ResolvedEnvironmentOptions = topLevelConfig.environments[name],
) {
// only allow some characters so that we can use name without escaping for directory names
// and make users easier to access with `environments.*`
if (!/^[\w$]+$/.test(name)) {
throw new Error(
`Invalid environment name "${name}". Environment names must only contain alphanumeric characters and "$", "_".`,
)
}
this.name = name
this._topLevelConfig = topLevelConfig
this._options = options
Expand Down

0 comments on commit 185352a

Please sign in to comment.