From ee11358d7fe30c0a78af1d632058d9ce8584e869 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Wed, 2 Aug 2017 14:57:02 -0700 Subject: [PATCH] null or empty strings should be omitted --- src/serialization.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/serialization.cpp b/src/serialization.cpp index 0894b0d..ef08e22 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -41,7 +41,7 @@ struct WriteArray { template void WriteOptionalString(JsonWriter& w, T& k, const char* value) { - if (value) { + if (value && value[0]) { w.Key(k, sizeof(T) - 1); w.String(value); } @@ -97,8 +97,10 @@ size_t JsonWriteRichPresenceObj(char* dest, } } - if (presence->largeImageKey || presence->largeImageText || - presence->smallImageKey || presence->smallImageText) { + if ((presence->largeImageKey && presence->largeImageKey[0]) || + (presence->largeImageText && presence->largeImageText[0]) || + (presence->smallImageKey && presence->smallImageKey[0]) || + (presence->smallImageText && presence->smallImageText[0])) { WriteObject assets(writer, "assets"); WriteOptionalString(writer, "large_image", presence->largeImageKey); WriteOptionalString(writer, "large_text", presence->largeImageText); @@ -106,7 +108,8 @@ size_t JsonWriteRichPresenceObj(char* dest, WriteOptionalString(writer, "small_text", presence->smallImageText); } - if (presence->partyId || presence->partySize || presence->partyMax) { + if ((presence->partyId && presence->partyId[0]) || presence->partySize || + presence->partyMax) { WriteObject party(writer, "party"); WriteOptionalString(writer, "id", presence->partyId); if (presence->partySize) { @@ -118,7 +121,9 @@ size_t JsonWriteRichPresenceObj(char* dest, } } - if (presence->matchSecret || presence->joinSecret || presence->spectateSecret) { + if ((presence->matchSecret && presence->matchSecret[0]) || + (presence->joinSecret && presence->joinSecret[0]) || + (presence->spectateSecret && presence->joinSecret[0])) { WriteObject secrets(writer, "secrets"); WriteOptionalString(writer, "match", presence->matchSecret); WriteOptionalString(writer, "join", presence->joinSecret);