From 69c56d539b21066d3e532ff44c9089e1f4ad43e8 Mon Sep 17 00:00:00 2001 From: Pavel Volkov Date: Sun, 14 Jan 2024 17:32:17 +0300 Subject: [PATCH 1/7] Fix infinite sub expire date --- lib/features/profile/data/profile_parser.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index c482ae2c4..8b2b66f7a 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -92,13 +92,12 @@ abstract class ProfileParser { "expire": final expire }) { total = total ?? 0; + expire = expire ?? 92233720368; return SubscriptionInfo( upload: upload, download: download, total: total == 0 ? 9223372036854775807 : total, - expire: DateTime.fromMillisecondsSinceEpoch( - (expire ?? 92233720368) * 1000, - ), + expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), ); } return null; From 07d5af80ec1f8d9acf8b1cb0f791d4bbbea367c5 Mon Sep 17 00:00:00 2001 From: Pavel Volkov Date: Sun, 14 Jan 2024 22:41:47 +0300 Subject: [PATCH 2/7] fix expire --- lib/features/profile/data/profile_parser.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index 8b2b66f7a..b970ace40 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -92,12 +92,12 @@ abstract class ProfileParser { "expire": final expire }) { total = total ?? 0; - expire = expire ?? 92233720368; + expire = expire ?? 0; return SubscriptionInfo( upload: upload, download: download, total: total == 0 ? 9223372036854775807 : total, - expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), + expire: expire == 0 ? DateTime.fromMillisecondsSinceEpoch(92233720368 * 1000) : DateTime.fromMillisecondsSinceEpoch(expire * 1000), ); } return null; From a48dda90a3d63bec0ec9be9b6f4862b41d7e2d08 Mon Sep 17 00:00:00 2001 From: Pavel Volkov Date: Mon, 15 Jan 2024 12:32:22 +0300 Subject: [PATCH 3/7] fix build --- lib/features/profile/data/profile_parser.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index b970ace40..2931e3c36 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -89,7 +89,7 @@ abstract class ProfileParser { "upload": final upload?, "download": final download?, "total": var total, - "expire": final expire + "expire": var expire }) { total = total ?? 0; expire = expire ?? 0; From 9cb3e0434661b2599b7d228f3a86cffaabc645c0 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:53:47 +0100 Subject: [PATCH 4/7] refactor --- lib/features/profile/data/profile_parser.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index 2931e3c36..1af284598 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -91,13 +91,13 @@ abstract class ProfileParser { "total": var total, "expire": var expire }) { - total = total ?? 0; - expire = expire ?? 0; + total = (total ?? 0) == 0 ? 9223372036854775807 : total; + expire = (expire ?? 0) == 0 ? 92233720368 : expire; return SubscriptionInfo( upload: upload, download: download, - total: total == 0 ? 9223372036854775807 : total, - expire: expire == 0 ? DateTime.fromMillisecondsSinceEpoch(92233720368 * 1000) : DateTime.fromMillisecondsSinceEpoch(expire * 1000), + total: total, + expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), ); } return null; From 645248e18379e4f68a932eebd2739a40069caed0 Mon Sep 17 00:00:00 2001 From: Hiddify <114227601+hiddify-com@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:08:17 +0100 Subject: [PATCH 5/7] make it better readable --- lib/features/profile/data/profile_parser.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index 1af284598..c1bcb0fcd 100644 --- a/lib/features/profile/data/profile_parser.dart +++ b/lib/features/profile/data/profile_parser.dart @@ -88,16 +88,16 @@ abstract class ProfileParser { case { "upload": final upload?, "download": final download?, - "total": var total, - "expire": var expire + "total": final total, + "expire": final expire }) { - total = (total ?? 0) == 0 ? 9223372036854775807 : total; - expire = (expire ?? 0) == 0 ? 92233720368 : expire; + final total1 = (total ==null || total== 0) ? 9223372036854775807 : total!; + final expire1 = (expire ==null || expire == 0) ? 92233720368 : expire!; return SubscriptionInfo( upload: upload, download: download, - total: total, - expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), + total: total1, + expire: DateTime.fromMillisecondsSinceEpoch(expire1 * 1000), ); } return null; From 788c683cf0d7e23e8b9e8ca17fb0a6ba818d9886 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Mon, 15 Jan 2024 20:10:21 +0330 Subject: [PATCH 6/7] Fix infinite sub --- lib/features/profile/data/profile_parser.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/features/profile/data/profile_parser.dart b/lib/features/profile/data/profile_parser.dart index c1bcb0fcd..e3c18140a 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, @@ -88,16 +91,16 @@ abstract class ProfileParser { case { "upload": final upload?, "download": final download?, - "total": final total, - "expire": final expire + "total": var total, + "expire": var expire }) { - final total1 = (total ==null || total== 0) ? 9223372036854775807 : total!; - final expire1 = (expire ==null || expire == 0) ? 92233720368 : expire!; + total = (total == null || total == 0) ? infiniteTrafficThreshold : total; + expire = (expire == null || expire == 0) ? infiniteTimeThreshold : expire; return SubscriptionInfo( upload: upload, download: download, - total: total1, - expire: DateTime.fromMillisecondsSinceEpoch(expire1 * 1000), + total: total, + expire: DateTime.fromMillisecondsSinceEpoch(expire * 1000), ); } return null; From 5dec73cf411ad009bd4072af86db109edb052638 Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Mon, 15 Jan 2024 20:10:31 +0330 Subject: [PATCH 7/7] Add test for infinite sub --- .../profile/data/profile_parser_test.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/features/profile/data/profile_parser_test.dart b/test/features/profile/data/profile_parser_test.dart index 96737245c..f02073913 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, + ), + ), + ); + }, + ); }, ); }