Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix #437: Add undefined check before using toLowerCase (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Zöllner authored and Josh Goldberg committed Oct 2, 2018
1 parent c32dec7 commit d3fb2f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/reactA11yImageButtonHasAltRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ReactA11yImageButtonHasAltWalker extends Lint.RuleWalker {
if (!typeAttribute
|| typeAttribute.initializer === undefined
|| !isStringLiteral(typeAttribute.initializer)
|| getStringLiteral(typeAttribute) === undefined
|| getStringLiteral(typeAttribute)!.toLowerCase() !== 'image') {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions src/tests/ReactA11yImageButtonHasAltRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ describe('reactA11yImageButtonHasAlt', (): void => {

TestHelper.assertNoViolation(ruleName, script);
});

it("when input element has an expression for its type thats undefined.", (): void => {
const script: string = `
import React = require('react');
const type = undefined;
const a = <input type={type} />;
`;

TestHelper.assertNoViolation(ruleName, script);
});
});

describe('should fail', (): void => {
Expand Down

0 comments on commit d3fb2f3

Please sign in to comment.