Sanity-check that options.maxCount is an int before "adding" it. #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Try this:
The character count will look like "-123,123" due to the arithmetic in the reverseCount function and JavaScript's usage of the + operator to append strings:
That's slightly amusing breakage. Whenever JS sees a string on one side of a + operator, it seems to convert the other side to a string and then append them.
Why am I passing a string in the
maxCount
param? Because I have adata-softlimit
parameter on the input fields which I'm using to get the character limit, which in this case is more of a "suggested" limit than a hard one, from the back end to the front end. So my code looks something like:…But a similar issue could probably happen if I were doing something more common like getting the limit from
$e.attr('maxlength')
.I could make the int on my side, but why not idiot-proof it in the library itself? It's just a one-line fix; I don't think we need to
parseInt(options.maxCount)
elsewhere because in most other places, we're subtracting with this value, not adding it - or casting it to a string anyway.