mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
1 parent
ae7586e313
commit
4e4866d1cd
3 files changed
+17
-1
No files matched your search
@@ -112,6 +112,7 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
|
||||
// First, remove any chars not in A-Za-z0-9_-. This will effectively get rid of any Unicode char, emojis etc too.
|
||||
std::string sanitized;
|
||||
sanitized.reserve(input.size());
|
||||
bool lastWasLineBreak = false;
|
||||
for (auto c : input) {
|
||||
switch (restriction) {
|
||||
case StringRestriction::None:
|
||||
@@ -125,6 +126,17 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
|
||||
sanitized.push_back(c);
|
||||
}
|
||||
break;
|
||||
case StringRestriction::NoLineBreaksOrSpecials:
|
||||
if (c >= 32) {
|
||||
sanitized.push_back(c);
|
||||
lastWasLineBreak = false;
|
||||
} else if (c == 10 || c == 13) {
|
||||
// Collapse line breaks/feeds to single spaces.
|
||||
if (!lastWasLineBreak) {
|
||||
sanitized.push_back(' ');
|
||||
}
|
||||
lastWasLineBreak = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ bool containsNoCase(std::string_view haystack, std::string_view needle);
|
||||
enum class StringRestriction {
|
||||
None,
|
||||
AlphaNumDashUnderscore, // Used for infrastructure usernames
|
||||
NoLineBreaksOrSpecials, // Used for savedata UI. Removes line breaks, backslashes and similar.
|
||||
};
|
||||
|
||||
std::string SanitizeString(std::string_view username, StringRestriction restriction, int minLength, int maxLength);
|
||||
|
||||
@@ -698,7 +698,10 @@ UI::EventReturn SavedataScreen::OnSavedataButtonClick(UI::EventParams &e) {
|
||||
if (!ginfo->Ready(GameInfoFlags::PARAM_SFO)) {
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
SavedataPopupScreen *popupScreen = new SavedataPopupScreen(gamePath_, Path(e.s), ginfo->GetTitle());
|
||||
|
||||
// Sanitize the title.
|
||||
std::string title = SanitizeString(ginfo->GetTitle(), StringRestriction::NoLineBreaksOrSpecials, 0, 200);
|
||||
SavedataPopupScreen *popupScreen = new SavedataPopupScreen(gamePath_, Path(e.s), title);
|
||||
if (e.v) {
|
||||
popupScreen->SetPopupOrigin(e.v);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user