format: sanitize username for null

ref #64
This commit is contained in:
Vaxry 2024-02-23 13:04:08 +00:00
parent f85287a523
commit 4c68780143

View file

@ -48,8 +48,13 @@ static std::string getTime() {
IWidget::SFormatResult IWidget::formatString(std::string in) { IWidget::SFormatResult IWidget::formatString(std::string in) {
char* username = getlogin();
if (!username)
Debug::log(ERR, "Error in formatString, username null. Errno: ", errno);
IWidget::SFormatResult result; IWidget::SFormatResult result;
replaceAll(in, "$USER", std::string{getlogin()}); replaceAll(in, "$USER", std::string{username ? username : ""});
replaceAll(in, "<br/>", std::string{"\n"}); replaceAll(in, "<br/>", std::string{"\n"});
if (in.contains("$TIME")) { if (in.contains("$TIME")) {