Skip to content

Commit

Permalink
Fix bug in float parsing regex
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Nov 4, 2019
1 parent 91737d0 commit 49d464f
Show file tree
Hide file tree
Showing 8 changed files with 545 additions and 192 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.3.1 (November 4, 2019)

Fix bug in float parsing regex

## 1.3.0 (September 16, 2019)

Add AWS Secrets Manager connection timeout
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "config-dug",
"version": "1.3.0",
"version": "1.3.1",
"description": "Config loader with support for AWS Secrets Manager",
"author": "Neo Financial Engineering <engineering@neofinancial.com>",
"main": "build/index.js",
Expand Down Expand Up @@ -45,8 +45,8 @@
"@types/debug": "^4.1.4",
"@types/jest": "^24.0.14",
"@types/node": "^12.0.8",
"eslint": "^5.16.0",
"eslint-config-neo": "^0.3.0",
"eslint": "^6.6.0",
"eslint-config-neo": "^0.4.2",
"husky": "^1.3.1",
"jest": "^24.8.0",
"lint-staged": "^8.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const loadFile = (filePath: string): object => {
const convertString = (value: string): string | number | boolean => {
if (value.toLowerCase() === 'true') return true;
if (value.toLowerCase() === 'false') return false;
if (value.match(/^\d+.\d+$/)) return parseFloat(value);
if (value.match(/^\d+\.\d+$/)) return parseFloat(value);
if (value.match(/^\d+$/)) return parseInt(value, 10);

return value;
Expand Down
4 changes: 3 additions & 1 deletion test/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test('loading config from environment variable works', (): void => {
process.env.KEY_3 = 'true';
process.env.KEY_4 = '42';
process.env.KEY_5 = '4.2';
process.env.KEY_11 = '123456,123456';

const testConfig = loadConfig('test/fixtures/typescript');

Expand All @@ -16,7 +17,8 @@ test('loading config from environment variable works', (): void => {
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar'
KEY_9: 'bar',
KEY_11: '123456,123456'
});

delete process.env.KEY_3;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/secrets/aws-secrets-manager-response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "/aws/reference/secretsmanager/development/config-dug",
"Type": "SecureString",
"Value": "{\"DB_USERNAME\":\"config-dug\",\"DB_PASSWORD\":\"secret\",\"TEST_BOOLEAN\":\"true\",\"TEST_INTEGER\":\"42\",\"TEST_FLOAT\":\"4.2\"}",
"Value": "{\"DB_USERNAME\":\"config-dug\",\"DB_PASSWORD\":\"secret\",\"TEST_BOOLEAN\":\"true\",\"TEST_INTEGER\":\"42\",\"TEST_FLOAT\":\"4.2\",\"TEST_NUMBER_LIST\":\"123456,123456\"}",
"Version": 0,
"SourceResult": "{\"ARN\":\"arn:aws:secretsmanager:us-east-1:999999999999:secret:development/config-dug-qH33bS\",\"name\":\"development/config-dug\",\"versionId\":\"8439a2e1-9a24-49ff-b9e7-5e8ba5d6d5a6\",\"secretString\":\"{\\\"DB_USERNAME\\\":\\\"config-dug\\\",\\\"DB_PASSWORD\\\":\\\"secret\\\"}\",\"versionStages\":[\"AWSCURRENT\"],\"createdDate\":\"Apr 10, 2019 10:49:20 PM\"}",
"LastModifiedDate": "2019-04-10T22:49:20.589Z",
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('loading TypeScript config works', (): void => {
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar',
KEY_9: 'bar'
});
});

Expand All @@ -26,7 +26,7 @@ test('loading JavaScript config works', (): void => {
KEY_5: 4.2,
KEY_7: 'local key',
KEY_8: 1,
KEY_9: 'bar',
KEY_9: 'bar'
});
});

Expand Down
3 changes: 2 additions & 1 deletion test/secrets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('loading secrets from AWS Secrets Manager works', (): void => {
DB_PASSWORD: 'secret',
TEST_BOOLEAN: true,
TEST_INTEGER: 42,
TEST_FLOAT: 4.2
TEST_FLOAT: 4.2,
TEST_NUMBER_LIST: '123456,123456'
});
});
Loading

0 comments on commit 49d464f

Please sign in to comment.