Skip to content

Commit

Permalink
Fix: Boolean fetch env 'false' value bugs (#99)
Browse files Browse the repository at this point in the history
* Fix: Boolean class doesnt convert strings to boolean

Boolean('false') returns true; Use string equallity to properly identify if string is true or false.

* Fix: properly handle envs whos value is boolean false

Previously we didnt properly handle a boolean false value, it would just make it look like it failed to get the value. This will strictly check whether value is defined or not.
  • Loading branch information
alewitt2 authored Apr 23, 2020
1 parent bdb41ad commit 03272f3
Show file tree
Hide file tree
Showing 3 changed files with 1,034 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/FetchEnvs.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = class FetchEnvs {
result = Number(result);
break;
case 'boolean':
result = Boolean(result);
result = (result === 'true');
break;
case 'json':
result = JSON.parse(result);
Expand Down Expand Up @@ -200,7 +200,7 @@ module.exports = class FetchEnvs {
result[name] = e.value;
} else if (e.valueFrom) {
let value = await this._lookupDataReference(e.valueFrom);
if (!value && !defaultValue) {
if (value === undefined && defaultValue === undefined) {
let msg = `${JSON.stringify(e.valueFrom)} not found: optional=${optional}`;
if (!optional) {
throw new Error(msg);
Expand All @@ -209,9 +209,9 @@ module.exports = class FetchEnvs {
this.updateRazeeLogs('info', { controller: 'FetchEnvs', warn: msg });
}
} else {
if (value) {
if (value !== undefined) {
result[name] = value;
} else if (defaultValue) {
} else if (defaultValue !== undefined) {
result[name] = defaultValue;

let msg = `${JSON.stringify(e.valueFrom)} not found. Using default value.`;
Expand Down
Loading

0 comments on commit 03272f3

Please sign in to comment.