File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ export type PluginConfig = {
1515export function parseEnvInt ( key : string , fallback : number ) : number {
1616 const raw = process . env [ key ]
1717 if ( ! raw ) return fallback
18- const n = parseInt ( raw , 10 )
19- return Number . isFinite ( n ) && n > 0 ? n : fallback
18+ if ( ! / ^ [ 1 - 9 ] \d * $ / . test ( raw ) ) return fallback
19+ const n = Number ( raw )
20+ return Number . isSafeInteger ( n ) ? n : fallback
2021}
2122
2223/**
Original file line number Diff line number Diff line change @@ -29,7 +29,12 @@ describe("parseEnvInt", () => {
2929
3030 test ( "returns fallback for float string" , ( ) => {
3131 process . env [ "TEST_INT" ] = "1.5"
32- expect ( parseEnvInt ( "TEST_INT" , 42 ) ) . toBe ( 1 )
32+ expect ( parseEnvInt ( "TEST_INT" , 42 ) ) . toBe ( 42 )
33+ } )
34+
35+ test ( "returns fallback for partial numeric string" , ( ) => {
36+ process . env [ "TEST_INT" ] = "5000ms"
37+ expect ( parseEnvInt ( "TEST_INT" , 42 ) ) . toBe ( 42 )
3338 } )
3439
3540 afterEach ( ( ) => { delete process . env [ "TEST_INT" ] } )
You can’t perform that action at this time.
0 commit comments