mirror of
https://github.com/aluxnimm/outlookcaldavsynchronizer.git
synced 2025-10-06 00:12:52 +02:00
Remove invalid xml chars from appointment and task strings.
This commit is contained in:
@@ -23,6 +23,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using DDay.iCal;
|
||||
using log4net;
|
||||
|
||||
@@ -209,10 +210,45 @@ namespace CalDavSynchronizer.DDayICalWorkaround
|
||||
return iCalendarData.Replace("\r\r\n", "\r\n");
|
||||
}
|
||||
|
||||
public static string EncodeString(string value)
|
||||
{
|
||||
string escaped = EscapeBackslash(value);
|
||||
return RemoveInvalidXmlChars(escaped);
|
||||
}
|
||||
|
||||
public static string EscapeBackslash(string value)
|
||||
{
|
||||
// DDay.iCal doesn't escape Backslash which leads to errors with some servers
|
||||
return value?.Replace(@"\", @"\\");
|
||||
return value?.Replace(@"\", @"\\");
|
||||
}
|
||||
|
||||
public static string RemoveInvalidXmlChars(string value)
|
||||
{
|
||||
const char _replacementCharacter = '\uFFFD';
|
||||
if (string.IsNullOrEmpty(value))
|
||||
return value;
|
||||
|
||||
int length = value.Length;
|
||||
StringBuilder stringBuilder = new StringBuilder(length);
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
if (XmlConvert.IsXmlChar(value[i]))
|
||||
{
|
||||
stringBuilder.Append(value[i]);
|
||||
}
|
||||
else if (i + 1 < length && XmlConvert.IsXmlSurrogatePair(value[i + 1], value[i]))
|
||||
{
|
||||
stringBuilder.Append(value[i]);
|
||||
stringBuilder.Append(value[i + 1]);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append(_replacementCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -248,16 +248,16 @@ namespace CalDavSynchronizer.Implementation.Events
|
||||
target.IsAllDay = false;
|
||||
}
|
||||
|
||||
target.Summary = CalendarDataPreprocessor.EscapeBackslash(source.Subject);
|
||||
target.Summary = CalendarDataPreprocessor.EncodeString(source.Subject);
|
||||
if (!string.IsNullOrEmpty(target.Summary) &&
|
||||
target.Summary.StartsWith("Cancelled: "))
|
||||
target.Status = EventStatus.Cancelled;
|
||||
|
||||
target.Location = CalendarDataPreprocessor.EscapeBackslash(source.Location);
|
||||
target.Location = CalendarDataPreprocessor.EncodeString(source.Location);
|
||||
|
||||
if (_configuration.MapBody)
|
||||
{
|
||||
target.Description = CalendarDataPreprocessor.EscapeBackslash(source.Body);
|
||||
target.Description = CalendarDataPreprocessor.EncodeString(source.Body);
|
||||
|
||||
if (_configuration.MapRtfBodyToXAltDesc && !string.IsNullOrEmpty(source.Body))
|
||||
{
|
||||
|
@@ -80,10 +80,10 @@ namespace CalDavSynchronizer.Implementation.Tasks
|
||||
|
||||
public void Map1To2(ITaskItemWrapper source, ITodo target, iCalTimeZone localIcalTimeZone, IEntitySynchronizationLogger logger)
|
||||
{
|
||||
target.Summary = CalendarDataPreprocessor.EscapeBackslash(source.Inner.Subject);
|
||||
target.Summary = CalendarDataPreprocessor.EncodeString(source.Inner.Subject);
|
||||
|
||||
if (_configuration.MapBody)
|
||||
target.Description = CalendarDataPreprocessor.EscapeBackslash(source.Inner.Body);
|
||||
target.Description = CalendarDataPreprocessor.EncodeString(source.Inner.Body);
|
||||
|
||||
if (source.Inner.StartDate != OutlookUtility.OUTLOOK_DATE_NONE)
|
||||
{
|
||||
|
Reference in New Issue
Block a user