Skip to content

Commit

Permalink
#243 Escape xpath names when they contain tabs or quotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Jun 3, 2021
1 parent 3250104 commit 15d7749
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion uSync.Core/Tracking/SyncXmlTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,26 @@ private string MakeSelectionPath(XElement node, string keys)
var value = GetKeyValue(node, key);
if (!string.IsNullOrWhiteSpace(value))
{
selectionPath += $"[{key} = '{value}']";
selectionPath += $"[{key} = {EscapeXPathString(value)}]";
}

}

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<string>();
Expand Down

0 comments on commit 15d7749

Please sign in to comment.