api: Fix usage of int.parse that implicitly accepts hexadecimal #326
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.
Calling just
int.parse(s)
, without aradix:
argument, invokes a special behavior whereint.parse
not only accepts decimal strings like "42", but also hexadecimal strings like "0x2a".That's a bit unexpected. In any case it's definitely not something we want when interpreting any part of the Zulip API.
Fix the one place we had this in our own code. There remain two places it appears in the code generated by
json_serializable
; mark those with TODO comments. It'd be nice to fix those too, but realistically this quirk is unlikely to ever cause a problem, so it's not worth a lot of effort to resolve.(Note that this doesn't affect the bulk of places we have an int in the API types, because most of those are handled by jsonDecode before the
json_serializable
-generated code ever sees them. It only affects the keys ofMap<int, …>
structures.)It looks like there's no existing thread in the
json_serializable
tracker for this issue. The most closely related is from where the handling ofMap<int, …>
types was added in the first place:google/json_serializable.dart#434