From 435cab01c8cf7f29e873eb7d9711dd0ad2ead816 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 21 Mar 2024 10:00:16 +0000 Subject: [PATCH] deal with (possible, future) non-alnum config keys --- packages/backend/src/config.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 1e08a0f6a..8f814e452 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -367,9 +367,13 @@ function applyEnvOverrides(config: Source) { } } + function _step2name(step: string|number): string { + return step.toString().replaceAll(/[^a-z0-9]+/gi,'').toUpperCase(); + } + // this recurses down, bailing out if there's no config to override function _descend(thisConfig: any, name: string, thisStep: string | number, steps: (string | number)[]) { - name = `${name}${thisStep.toString().toUpperCase()}_`; + name = `${name}${_step2name(thisStep)}_`; thisConfig = thisConfig[thisStep]; if (!thisConfig) return; _apply_inner(thisConfig, name, steps); @@ -378,7 +382,7 @@ function applyEnvOverrides(config: Source) { // this is the bottom of the recursion: look at the environment and // set the value function _lastBit(thisConfig: any, name: string, lastStep: string | number) { - name = `${name}${lastStep.toString().toUpperCase()}`; + name = `${name}${_step2name(lastStep)}`; const val = process.env[`MK_CONFIG_${name}`]; if (val != null && val != undefined) {