From 322f0628e6cdc30726c72b7fae322cef6c8839c5 Mon Sep 17 00:00:00 2001 From: Fitz Date: Tue, 12 Apr 2022 18:07:32 -0700 Subject: [PATCH] Force utf8-decoding of Unsplash reponse (#586 & #590) (#1075) --- .../fluent_ui/lib/src/unsplash/unsplash.dart | 5 ++++- desktop_photo_search/material/lib/src/unsplash/unsplash.dart | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart b/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart index 09637a4d6..f2d497119 100644 --- a/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart +++ b/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart @@ -73,7 +73,10 @@ class Unsplash { } return SearchPhotosResponse.fromJson( - response.body, + // Per Response#body, if the Content-Type header is unknown, bodyBytes + // is interpreted as latin1. Unsplash returns utf8, but with no encoding + // specified in the Content-Type, so we must do it ourselves. + utf8.decode(response.bodyBytes), ); } diff --git a/desktop_photo_search/material/lib/src/unsplash/unsplash.dart b/desktop_photo_search/material/lib/src/unsplash/unsplash.dart index 09637a4d6..f2d497119 100644 --- a/desktop_photo_search/material/lib/src/unsplash/unsplash.dart +++ b/desktop_photo_search/material/lib/src/unsplash/unsplash.dart @@ -73,7 +73,10 @@ class Unsplash { } return SearchPhotosResponse.fromJson( - response.body, + // Per Response#body, if the Content-Type header is unknown, bodyBytes + // is interpreted as latin1. Unsplash returns utf8, but with no encoding + // specified in the Content-Type, so we must do it ourselves. + utf8.decode(response.bodyBytes), ); }