You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[convert] FixedDateTimeFormatter.tryDecode throws RangeError when the input is shorter than the pattern #1039
FixedDateTimeFormatter.tryDecode is documented to return null when the input doesn't match the pattern, but an input shorter than the pattern throws a RangeError. decode also throws RangeError here, not the documented FormatException.
import'package:convert/convert.dart';
voidmain() {
final f =FixedDateTimeFormatter('YYYYMMDD');
print(f.tryDecode('202401'));
}
Actual:
RangeError (length): Invalid value: Not in inclusive range 0..5: 6
Expected: null from tryDecode, and a FormatException from decode.
Cause: tryParse (pkgs/convert/lib/src/fixed_datetime_formatter.dart:325) loops to the block's end and calls codeUnitAt(i) without checking formattedDateTime.length.
Suggested fix: in tryParse, return null when end > formattedDateTime.length. The error message in _extractNumberFromString (line 312) also needs to clamp its substring end, or decode will still throw RangeError.
Activity
FMorschel commentedon Nov 3, 2026
CC @lrhn