diff --git a/uSync.Core/Tracking/SyncXmlTracker.cs b/uSync.Core/Tracking/SyncXmlTracker.cs index d2e02751..f4f0e0c8 100644 --- a/uSync.Core/Tracking/SyncXmlTracker.cs +++ b/uSync.Core/Tracking/SyncXmlTracker.cs @@ -192,7 +192,7 @@ private string MakeSelectionPath(XElement node, string keys) var value = GetKeyValue(node, key); if (!string.IsNullOrWhiteSpace(value)) { - selectionPath += $"[{key} = '{value}']"; + selectionPath += $"[{key} = {EscapeXPathString(value)}]"; } } @@ -200,6 +200,18 @@ private string MakeSelectionPath(XElement node, string keys) return selectionPath.Replace("][", " and "); } + private string EscapeXPathString(string value) + { + if (!value.Contains("'")) + return '\'' + value + '\''; + + if (!value.Contains("\"")) + return '"' + value + '"'; + + return "concat('" + value.Replace("'", "',\"'\",'") + "')"; + } + + private string MakeSelectionName(XElement node, string keys) { var names = new List();