From fd9ba46b7b265fc6b1beb0c61b02cf79398bfcea Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Wed, 5 Nov 2025 12:36:09 +0100 Subject: [PATCH] fix: allow malformed utf-8 --- lib/client/plex_client.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/client/plex_client.dart b/lib/client/plex_client.dart index 83907304..d496289b 100644 --- a/lib/client/plex_client.dart +++ b/lib/client/plex_client.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'package:dio/dio.dart'; import '../config/plex_config.dart'; import '../models/plex_library.dart'; @@ -22,6 +23,15 @@ class PlexClient { PlexConfig config; late final Dio _dio; + /// Custom response decoder that handles malformed UTF-8 gracefully + static String _lenientUtf8Decoder( + List responseBytes, + RequestOptions options, + ResponseBody responseBody, + ) { + return utf8.decode(responseBytes, allowMalformed: true); + } + PlexClient(this.config) { _dio = Dio( BaseOptions( @@ -32,6 +42,7 @@ class PlexClient { validateStatus: (status) => status != null && status < 500, responseType: ResponseType.json, contentType: 'application/json; charset=utf-8', + responseDecoder: _lenientUtf8Decoder, ), );