Skip to content

Commit

Permalink
Calculator: treat user input as invalid If math.eval returns undefined (
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Feb 8, 2019
1 parent fa49102 commit 514596f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe(CalculatorInputValidator.name, (): void => {

it("should return false when passing in an invalid argument", (): void => {
const invalidInputs = [
"#",
"#2",
"s",
"kg",
"log()",
Expand Down
4 changes: 4 additions & 0 deletions src/ts/calculator/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class Calculator {
} catch (e) {
return false;
}

if (result === undefined) {
return false;
}
return !isNaN(result) || this.isValidMathType(result) || false;
}

Expand Down

0 comments on commit 514596f

Please sign in to comment.