From 9524148de70e688365186b1c006bbb9d2867f8b6 Mon Sep 17 00:00:00 2001 From: Alexey Arutyunov Date: Sun, 3 Aug 2025 01:35:36 +0200 Subject: [PATCH] RuStore: fix charset detection (#2304) Decode whole response body in bytes and fallback to UTF-8 instead of auto-decoding individual fields. --- lib/app_sources/rustore.dart | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/app_sources/rustore.dart b/lib/app_sources/rustore.dart index 0b91f91..6589f96 100644 --- a/lib/app_sources/rustore.dart +++ b/lib/app_sources/rustore.dart @@ -36,13 +36,15 @@ class RuStore extends AppSource { return Uri.parse(standardUrl).pathSegments.last; } - Future decodeString(String str) async { + Future decodeJsonBody(Uint8List bytes) async { try { - return (await CharsetDetector.autoDecode( - Uint8List.fromList(str.codeUnits), - )).string; + return jsonDecode((await CharsetDetector.autoDecode(bytes)).string); } catch (e) { - return str; + try { + return jsonDecode(utf8.decode(bytes)); + } catch (_) { + rethrow; + } } } @@ -59,7 +61,7 @@ class RuStore extends AppSource { if (res0.statusCode != 200) { throw getObtainiumHttpError(res0); } - var appDetails = jsonDecode(res0.body)['body']; + var appDetails = (await decodeJsonBody(res0.bodyBytes))['body']; if (appDetails['appId'] == null) { throw NoReleasesError(); } @@ -83,15 +85,11 @@ class RuStore extends AppSource { followRedirects: false, postBody: {"appId": appDetails['appId'], "firstInstall": true}, ); - var downloadDetails = jsonDecode(res1.body)['body']; + var downloadDetails = (await decodeJsonBody(res1.bodyBytes))['body']; if (res1.statusCode != 200 || downloadDetails['apkUrl'] == null) { throw NoAPKError(); } - appName = await decodeString(appName); - author = await decodeString(author); - changeLog = changeLog != null ? await decodeString(changeLog) : null; - return APKDetails( version, getApkUrlsFromUrls([