From 0a2ffca84a81c95bb88e89f9c1eea5abe8540861 Mon Sep 17 00:00:00 2001 From: Awlad Hussain Date: Tue, 7 Nov 2023 12:10:00 +0000 Subject: [PATCH 1/2] fix for #14698 --- src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs index 87d4d459faf7..5f8f2f8118fb 100644 --- a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs +++ b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs @@ -112,6 +112,12 @@ public static string ParseXPathQuery( "$site", string.Format(rootXpath, closestPublishedAncestorId) + "/ancestor-or-self::*[@level = 1]"); }); + + vars.Add("$current", q => + { + var closestPublishedAncestorId = getClosestPublishedAncestor(getPath(parentId.Value)); + return q.Replace("$current", string.Format(rootXpath, closestPublishedAncestorId)); + }); } else if (nodeContextId.HasValue) { @@ -134,11 +140,7 @@ public static string ParseXPathQuery( "$site", string.Format(rootXpath, closestPublishedAncestorId) + "/ancestor-or-self::*[@level = 1]"); }); - } - // These parameters must have a node id context - if (nodeContextId.HasValue) - { vars.Add("$current", q => { var closestPublishedAncestorId = getClosestPublishedAncestor(getPath(nodeContextId.Value)); From dcc74e27254a560ce9855f6d65888f7c237f03b4 Mon Sep 17 00:00:00 2001 From: Laura Neto <12862535+lauraneto@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:38:20 +0100 Subject: [PATCH 2/2] Adjust XPath logic so it uses parentId as $current only when nodeContextId is null or 0 --- src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs index 5f8f2f8118fb..a3b194226c3e 100644 --- a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs +++ b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs @@ -112,12 +112,6 @@ public static string ParseXPathQuery( "$site", string.Format(rootXpath, closestPublishedAncestorId) + "/ancestor-or-self::*[@level = 1]"); }); - - vars.Add("$current", q => - { - var closestPublishedAncestorId = getClosestPublishedAncestor(getPath(parentId.Value)); - return q.Replace("$current", string.Format(rootXpath, closestPublishedAncestorId)); - }); } else if (nodeContextId.HasValue) { @@ -140,10 +134,14 @@ public static string ParseXPathQuery( "$site", string.Format(rootXpath, closestPublishedAncestorId) + "/ancestor-or-self::*[@level = 1]"); }); + } + if (nodeContextId.HasValue || parentId.HasValue) + { + var currentId = nodeContextId.HasValue && nodeContextId.Value != default ? nodeContextId.Value : parentId.GetValueOrDefault(); vars.Add("$current", q => { - var closestPublishedAncestorId = getClosestPublishedAncestor(getPath(nodeContextId.Value)); + var closestPublishedAncestorId = getClosestPublishedAncestor(getPath(currentId)); return q.Replace("$current", string.Format(rootXpath, closestPublishedAncestorId)); }); }