From 2bb89efe75ee470867c017c052e445f1f1ed4dfa Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 26 Aug 2015 17:13:34 +0200 Subject: [PATCH] Fix for XML encoding from membuffer --- Logic/Communications/Transmission/PayloadBase.cs | 7 ++++++- Logic/Support/LogEntries/LogEntryBase.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Logic/Communications/Transmission/PayloadBase.cs b/Logic/Communications/Transmission/PayloadBase.cs index 3b7411fd..1c44655b 100644 --- a/Logic/Communications/Transmission/PayloadBase.cs +++ b/Logic/Communications/Transmission/PayloadBase.cs @@ -17,7 +17,12 @@ namespace Swarmops.Logic.Communications.Transmission serializer.Serialize (stream, this); byte[] xmlBytes = stream.GetBuffer(); - return Encoding.UTF8.GetString (xmlBytes); + string xml = Encoding.UTF8.GetString (xmlBytes); + + xml = xml.Replace("�", ""); + xml = xml.Replace("\x00", ""); + + return xml; } public static T FromXml (string xml) diff --git a/Logic/Support/LogEntries/LogEntryBase.cs b/Logic/Support/LogEntries/LogEntryBase.cs index 31a37b71..f5729518 100644 --- a/Logic/Support/LogEntries/LogEntryBase.cs +++ b/Logic/Support/LogEntries/LogEntryBase.cs @@ -16,7 +16,12 @@ namespace Swarmops.Logic.Support.LogEntries serializer.Serialize (stream, this); byte[] xmlBytes = stream.GetBuffer(); - return Encoding.UTF8.GetString (xmlBytes); + string xml = Encoding.UTF8.GetString (xmlBytes); + + xml = xml.Replace("�", ""); + xml = xml.Replace("\x00", ""); + + return xml; } public static T FromXml (string xml) // 'T' might not work here, like it didn't in ToXml()