Commit 78775954 authored by Piotr Tomasik's avatar Piotr Tomasik Committed by Tim Neutkens

fix regex to not match any string with double underscore (#8153)

* fix regex to not match any string with double underscore

* add test for __ in env name and make existing test more descriptive.
parent 482f454c
......@@ -438,7 +438,7 @@ export default async function getBaseWebpackConfig(
new ChunkNamesPlugin(),
new webpack.DefinePlugin({
...Object.keys(config.env).reduce((acc, key) => {
if (/^(?:NODE_.+)|(?:__.+)$/i.test(key)) {
if (/^(?:NODE_.+)|^(?:__.+)$/i.test(key)) {
throw new Error(
`The key "${key}" under "env" in next.config.js is not allowed. https://err.sh/zeit/next.js/env-key-not-allowed`
)
......
......@@ -13,6 +13,11 @@ module.exports = withCSS(
? {
NODE_ENV: 'abc'
}
: {}),
...(process.env.ENABLE_ENV_WITH_UNDERSCORES
? {
SOME__ENV__VAR: '123'
}
: {})
},
onDemandEntries: {
......
......@@ -40,7 +40,7 @@ describe('Production Config Usage', () => {
})
describe('env', () => {
it('should fail with __ in env key', async () => {
it('should fail with leading __ in env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_UNDERSCORE: true },
stdout: true,
......@@ -59,6 +59,16 @@ describe('Production Config Usage', () => {
expect(result.stderr).toMatch(/The key "NODE_ENV" under/)
})
it('should allow __ within env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_WITH_UNDERSCORES: true },
stdout: true,
stderr: true
})
expect(result.stderr).not.toMatch(/The key "SOME__ENV__VAR" under/)
})
})
describe('with generateBuildId', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment