From 15d774955116caa50026c1fcbb552ca621e9b1bc Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Thu, 3 Jun 2021 11:50:06 +0100 Subject: [PATCH] #243 Escape xpath names when they contain tabs or quotes. --- uSync.Core/Tracking/SyncXmlTracker.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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();