From 23504e053dfa1d5a68a0dbc290b46b7ef22137a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hoh?= Date: Fri, 1 Mar 2024 14:54:59 +0100 Subject: [PATCH 01/43] LinkImpl: avoid redundant repository lookups (#2453) * avoid redundant repository lookups --- .../internal/link/LinkBuilderImpl.java | 61 +++++++++---------- .../internal/link/LinkBuilderImplTest.java | 18 ++++++ 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImpl.java index ff45f8a634..c09988db76 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImpl.java @@ -15,9 +15,9 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ package com.adobe.cq.wcm.core.components.internal.link; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.HashMap; import java.util.Optional; import org.apache.commons.lang3.StringUtils; @@ -135,16 +135,41 @@ public LinkBuilderImpl(String url, SlingHttpServletRequest req, List pair = resolvePage(page); this.reference = pair.getLeft(); linkUrl = StringUtils.isNotEmpty(pair.getRight()) ? pair.getRight() : linkUrl; + + // resolvePage() can resolve the linkUrl into an external URL; this can happen when + // there is a redirect from the page to an external URL; in this case + // the pair is not equivalent + isExternalUrl = !pair.getLeft().getPath().equals(linkUrl); + } + + String resolvedLinkURL = null; + if (this.reference != null && page != null && !isExternalUrl) { + resolvedLinkURL = getPageLinkURL((Page)this.reference); + } else if (StringUtils.isNotEmpty(linkUrl)) { + resolvedLinkURL = linkUrl; } - String resolvedLinkURL = validateAndResolveLinkURL(linkUrl); + Map htmlAttributes = mapLinkAttributesToHtml(); return buildLink(resolvedLinkURL, request, htmlAttributes); } @@ -213,34 +238,6 @@ private String validateLinkAttributeValue(@Nullable final String value) { .orElse(null); } - /** - * Validates and resolves a link URL. - * - * @param linkURL Link URL - * @return The validated link URL or {@code null} if not valid - */ - @Nullable - private String validateAndResolveLinkURL(@Nullable final String linkURL) { - return Optional.ofNullable(linkURL) - .filter(StringUtils::isNotEmpty) - .map(this::getLinkURL) - .orElse(null); - } - - /** - * If the provided {@code path} identifies a {@link Page}, this method will generate the correct URL for the page. Otherwise the - * original {@code String} is returned. - * @param path the page path - * - * @return the URL of the page identified by the provided {@code path}, or the original {@code path} if this doesn't identify a {@link Page} - */ - @NotNull - private String getLinkURL(@NotNull String path) { - return getPage(path) - .map(this::getPageLinkURL) - .orElse(path); - } - /** * Given a {@link Page}, this method returns the correct URL with the extension * @param page the page diff --git a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImplTest.java b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImplTest.java index 3c7602e8ea..783fa224de 100644 --- a/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImplTest.java +++ b/bundles/core/src/test/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImplTest.java @@ -26,6 +26,8 @@ import com.adobe.cq.wcm.core.components.commons.link.Link; import com.adobe.cq.wcm.core.components.services.link.PathProcessor; +import com.day.cq.dam.api.Asset; + import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; @@ -102,4 +104,20 @@ void testLinkToPage(String given, String expected, String passedDownToPathProces verify(pathProcessor).externalize(eq(passedDownToPathProcessor), any()); verify(pathProcessor).sanitize(eq(passedDownToPathProcessor), any()); } + + + void testLinkToAsset() { + Asset asset = context.create().asset("/content/dam/asset.jpg", 0, 0, "image/jpeg"); + + Link link = new LinkBuilderImpl(asset, context.request(),Collections.singletonList(pathProcessor)).build(); + assertEquals("/content/dam/asset.jpg", link.getURL()); + assertNotNull(link.getReference()); + assertEquals(asset,link.getReference()); + + link = new LinkBuilderImpl("/content/dam/asset.jpg", context.request(), Collections.singletonList(pathProcessor),false).build(); + assertEquals("/content/dam/asset.jpg", link.getURL()); + assertEquals("/content/dam/asset.jpg", ((Asset) link.getReference()).getPath()); + + + } } From 2226de3518505182cf527dc7d4dce38f827f9a59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:17:20 +0200 Subject: [PATCH 02/43] Bump the maven group across 2 directories with 1 update (#2669) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates `org.apache.sling:org.apache.sling.api` from 2.22.0 to 2.25.4 for `test` scope --- updated-dependencies: - dependency-name: org.apache.sling:org.apache.sling.api dependency-type: direct:development dependency-group: maven-security-group ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Levente Sántha Co-authored-by: Vlad --- bundles/core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/core/pom.xml b/bundles/core/pom.xml index 94d0d8e4a9..c89bd6e94a 100644 --- a/bundles/core/pom.xml +++ b/bundles/core/pom.xml @@ -438,7 +438,7 @@ org.apache.sling org.apache.sling.api - 2.22.0 + 2.25.4 test From efb0bde94c5769dc8f28c49e9cbf18c6f124d82d Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 2 Mar 2024 11:30:04 +0200 Subject: [PATCH 03/43] Update Sling i18n dependency for `test` scope (#2690) --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index ee93ef8815..89ee61db58 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -825,7 +825,7 @@ org.apache.sling org.apache.sling.i18n - 2.5.14 + 2.6.2 test From 55a9b8d9d7598fdf045974b4c0f13921852addcb Mon Sep 17 00:00:00 2001 From: korben-ne-dallas Date: Sat, 2 Mar 2024 11:19:29 +0100 Subject: [PATCH 04/43] [ClientLibraries] Add option to inject the onload attribute into the stylesheet link tag (#2296) * [ClientLibraries] Add option to inject the onload attribute into the stylesheet link tag * [ClientLibraries] Inject existing onload attribute into the stylesheet link tag Fixes #2295 --- .../components/internal/models/v1/ClientLibrariesImpl.java | 1 + .../internal/models/v1/ClientLibrariesImplTest.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java index cad694e5a5..7c11ef98aa 100644 --- a/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java +++ b/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ClientLibrariesImpl.java @@ -208,6 +208,7 @@ private String getHtmlWithInjectedAttributes(String html) { jsAttributes.append(getHtmlAttr(OPTION_ONLOAD, onload)); StringBuilder cssAttributes = new StringBuilder(); cssAttributes.append(getHtmlAttr(OPTION_MEDIA, media)); + cssAttributes.append(getHtmlAttr(OPTION_ONLOAD, onload)); String updatedHtml = StringUtils.replace(html,"