diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index c482ae2c..e3c18140 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -14,6 +14,9 @@ import 'package:uuid/uuid.dart'; /// - url filename extension (example: `https://example.com/config.json`) -> name=`config` /// - if none of these methods return a non-blank string, fallback to `Remote Profile` abstract class ProfileParser { + static const infiniteTrafficThreshold = 9223372036854775807; + static const infiniteTimeThreshold = 92233720368; + static RemoteProfileEntity parse( String url, Map> headers, @@ -89,16 +92,15 @@ abstract class ProfileParser { "upload": final upload?, "download": final download?, "total": var total, - "expire": final expire + "expire": var expire }) { - total = total ?? 0; + total = (total == null || total == 0) ? infiniteTrafficThreshold : total; + expire = (expire == null || expire == 0) ? infiniteTimeThreshold : expire; return SubscriptionInfo( upload: upload, download: download, - total: total == 0 ? 9223372036854775807 : total, - expire: DateTime.fromMillisecondsSinceEpoch( - (expire ?? 92233720368) * 1000, - ), + total: total, + expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), ); } return null; diff --git a/test/features/profile/data/profile_parser_test.dart b/test/features/profile/data/profile_parser_test.dart index 96737245..f0207391 100644 --- a/test/features/profile/data/profile_parser_test.dart +++ b/test/features/profile/data/profile_parser_test.dart @@ -70,6 +70,36 @@ void main() { ); }, ); + + test( + "with infinite traffic and time", + () { + final headers = >{ + "profile-title": ["title"], + "profile-update-interval": ["1"], + "subscription-userinfo": [ + "upload=0;download=1024;total=0;expire=0", + ], + "profile-web-page-url": [validBaseUrl], + "support-url": [validSupportUrl], + }; + final profile = ProfileParser.parse(validExtendedUrl, headers); + + expect(profile.subInfo, isNotNull); + expect( + profile.subInfo!.total, + equals(ProfileParser.infiniteTrafficThreshold), + ); + expect( + profile.subInfo!.expire, + equals( + DateTime.fromMillisecondsSinceEpoch( + ProfileParser.infiniteTimeThreshold * 1000, + ), + ), + ); + }, + ); }, ); }