Additional fixes for stringified IDs in JSON

These should be the last two. These were identified using eslint to try
to identify any plain casts to JavaScript numbers. (Some such casts are
legitimate, but these were not.)

Adding the following to .eslintrc.yml will identify casts to numbers:

~~~
  no-restricted-syntax:
  - warn
  - selector: UnaryExpression[operator='+'] > :not(Literal)
    message: Avoid the use of unary +
  - selector: CallExpression[callee.name='Number']
    message: Casting with Number() may coerce string IDs to numbers
~~~

The remaining three casts appear legitimate: two casts to array indices,
one in a server to turn an environment variable into a number.
This commit is contained in:
aschmitz 2017-09-18 22:48:39 -05:00
parent 44a753a6f3
commit fdca411888
2 changed files with 2 additions and 2 deletions

View File

@ -128,7 +128,7 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
} }
onSuggestionClick = (e) => { onSuggestionClick = (e) => {
const suggestion = Number(e.currentTarget.getAttribute('data-index')); const suggestion = e.currentTarget.getAttribute('data-index');
e.preventDefault(); e.preventDefault();
this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestion); this.props.onSuggestionSelected(this.state.tokenStart, this.state.lastToken, suggestion);
this.textarea.focus(); this.textarea.focus();

View File

@ -21,7 +21,7 @@ export default class UploadForm extends React.PureComponent {
}; };
onRemoveFile = (e) => { onRemoveFile = (e) => {
const id = Number(e.currentTarget.parentElement.getAttribute('data-id')); const id = e.currentTarget.parentElement.getAttribute('data-id');
this.props.onRemoveFile(id); this.props.onRemoveFile(id);
} }