Skip to content

Commit

Permalink
Merge pull request #1635 from raccoonback/check-nullable-args-in-tran…
Browse files Browse the repository at this point in the history
…slator-exist

change to return false when a nullable argument is passed
  • Loading branch information
jamuhl committed Aug 4, 2021
2 parents b371a5c + f9f3817 commit d0dc508
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Translator extends EventEmitter {
}

exists(key, options = { interpolation: {} }) {
if (key === undefined || key === null) {
return false;
}

const resolved = this.resolve(key, options);
return resolved && resolved.res !== undefined;
}
Expand Down
8 changes: 8 additions & 0 deletions test/translator/translator.exists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,13 @@ describe('Translator', () => {
expect(t.exists.apply(t, test.args)).to.eql(test.expected);
});
});

const nullishArgs = ['', undefined, null];

nullishArgs.forEach(nullishArg => {
it(`should return false if a "${nullishArg}" key is passed as an argument`, () => {
expect(t.exists(nullishArg)).to.false;
});
});
});
});

0 comments on commit d0dc508

Please sign in to comment.