File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -64,15 +64,27 @@ export function loadConfig() {
6464 * Parses environment variable JSON strings into JS objects
6565 */
6666function parseNestedJson ( config : any ) : ApplicationConfig {
67- return Object . keys ( config ) . reduce ( ( accumulator , configKey ) => {
67+ // Only parse values that are JSON objects or arrays. We avoid
68+ // coercing simple primitives like numbers or booleans that happen
69+ // to be valid JSON (e.g. "1.0") because env vars are expected to
70+ // remain strings unless explicitly JSON objects/arrays.
71+ const initial = { ...config } ;
72+ return Object . keys ( initial ) . reduce ( ( accumulator , configKey ) => {
73+ const raw = initial [ configKey ] ;
74+ if ( typeof raw !== 'string' ) return accumulator ;
75+
6876 try {
69- accumulator [ configKey ] = JSON . parse ( config [ configKey ] ) ;
77+ const parsed = JSON . parse ( raw ) ;
78+ // Only replace when parsing yields an object or array
79+ if ( parsed !== null && ( typeof parsed === 'object' || Array . isArray ( parsed ) ) ) {
80+ accumulator [ configKey ] = parsed ;
81+ }
7082 } catch {
71- /* empty */
83+ // leave original string value
7284 }
7385
74- return config ;
75- } , config ) ;
86+ return accumulator ;
87+ } , initial ) as ApplicationConfig ;
7688}
7789
7890/**
You can’t perform that action at this time.
0 commit comments