mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-25 12:34:45 -04:00
Safely parse numbers from environment vars
This adds the function parseOptionalInt to help parse numbers from environment variables Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
36e721d4a9
commit
52f6310e91
5 changed files with 23 additions and 8 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
import {
|
||||
needToLog,
|
||||
parseOptionalInt,
|
||||
replaceAuthErrorsWithEnvironmentVariables,
|
||||
toArrayConfig,
|
||||
} from './utils';
|
||||
|
@ -84,4 +85,12 @@ describe('config utils', () => {
|
|||
expect(needToLog(currentLevel, Loglevel.TRACE)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
describe('parseOptionalInt', () => {
|
||||
it('returns undefined on undefined parameter', () => {
|
||||
expect(parseOptionalInt(undefined)).toEqual(undefined);
|
||||
});
|
||||
it('correctly parses a string', () => {
|
||||
expect(parseOptionalInt('42')).toEqual(42);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue