From abff8a078f0546609d311c1775e517d0131bfa3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 9 Apr 2025 11:58:56 +0200 Subject: [PATCH] Work around bad null decoding (overlong) in Jak & Daxter savedata title. --- Common/StringUtils.cpp | 7 +++++++ UI/SavedataScreen.cpp | 3 +++ 2 files changed, 10 insertions(+) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 845eddc674..b179d363b2 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -161,6 +161,13 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction } } + if (restriction == StringRestriction::NoLineBreaksOrSpecials) { + // Additionally, cut off the string if we find an overlong UTF-8 character, such as in Jak & Daxter's title. + size_t pos = sanitized.find("\xc0\x80"); + if (pos != (size_t)std::string::npos) { + sanitized.resize(pos); + } + } return sanitized; } diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index 4bd1dcbafb..32853ae262 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -65,6 +65,7 @@ SavedataView::SavedataView(UIContext &dc, const Path &savePath, IdentifiedFileTy if (showIcon) { toprow->Add(new GameIconView(savePath, 2.0f, new LinearLayoutParams(Margins(5, 5)))); } + // Contents to the right of the image: LinearLayout *topright = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 1.0f)); topright->SetSpacing(1.0f); savedataTitle_ = topright->Add(new TextView(savedataTitle, ALIGN_LEFT | FLAG_WRAP_TEXT, false)); @@ -74,6 +75,8 @@ SavedataView::SavedataView(UIContext &dc, const Path &savePath, IdentifiedFileTy mTime_ = topright->Add(new TextView(mtime, 0, true)); mTime_->SetTextColor(textStyle.fgColor); toprow->Add(topright); + + // Content below the image. Add(new Spacer(3.0)); detail_ = Add(new TextView(SanitizeString(savedataDetail, StringRestriction::ConvertToUnixEndings), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(Margins(10, 0)))); detail_->SetTextColor(textStyle.fgColor);