Cherry-pick #20142 for V16 (#20147)

* Support querystring and anchor for local links in Delivery API output (#20142)

* Support querystring and anchor for local links in Delivery API output

* Add default implementation for backwards compat

* Add default implementation for backwards compat (also on the interface)

* Fix default implementation

* Add extra tests proving that querystring/postfix can be handled for local links in both legacy and current format.
This commit is contained in:
Kenn Jacobsen
2025-09-16 11:33:40 +02:00
committed by GitHub
parent 4ae3bb3835
commit ef1aaf8bce
7 changed files with 121 additions and 6 deletions

View File

@@ -60,7 +60,7 @@ internal sealed class ApiRichTextMarkupParser : ApiRichTextParserBase, IApiRichT
link.GetAttributeValue("type", "unknown"),
route =>
{
link.SetAttributeValue("href", route.Path);
link.SetAttributeValue("href", $"{route.Path}{route.QueryString}");
link.SetAttributeValue("data-start-item-path", route.StartItem.Path);
link.SetAttributeValue("data-start-item-id", route.StartItem.Id.ToString("D"));
link.Attributes["type"]?.Remove();

View File

@@ -4,6 +4,7 @@ using Umbraco.Cms.Core.DeliveryApi;
using Umbraco.Cms.Core.Models.DeliveryApi;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.DeliveryApi;
@@ -58,6 +59,7 @@ internal abstract partial class ApiRichTextParserBase
: null;
if (route != null)
{
route.QueryString = match.Groups["query"].Value.NullOrWhiteSpaceAsNull();
handleContentRoute(route);
return ReplaceStatus.Success;
}
@@ -105,6 +107,7 @@ internal abstract partial class ApiRichTextParserBase
: null;
if (route != null)
{
route.QueryString = match.Groups["query"].Value.NullOrWhiteSpaceAsNull();
handleContentRoute(route);
return ReplaceStatus.Success;
}
@@ -140,10 +143,10 @@ internal abstract partial class ApiRichTextParserBase
handleMediaUrl(_apiMediaUrlProvider.GetUrl(media));
}
[GeneratedRegex("{localLink:(?<udi>umb:.+)}")]
[GeneratedRegex("{localLink:(?<udi>umb:.+)}(?<query>[^\"]*)")]
private static partial Regex LegacyLocalLinkRegex();
[GeneratedRegex("{localLink:(?<guid>.+)}")]
[GeneratedRegex("{localLink:(?<guid>.+)}(?<query>[^\"]*)")]
private static partial Regex LocalLinkRegex();
private enum ReplaceStatus