adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
733 stars 741 forks source link

[Link] LinkManager doesn't properly handle encoded URL parameters #2507

Open rubnig opened 1 year ago

rubnig commented 1 year ago

Bug Report

Current Behavior Building a Link object with the LinkManager, containing an external URL with a properly encoded URL parameter, breaks the URL encoding.

For example: a Twitter share link with the url parameter encoded, as is described in: https://developer.twitter.com/en/docs/twitter-for-websites/tweet-button/guides/web-intent#:~:text=Hello%2520World-,url,t.co%C2%A0to%20the%20number%20of%20characters%20specified%20by%C2%A0short_url_length.,-https%253A%252F

build with the LinkManager, so all links are handled in the same way, link target can be controlled and so it can directly be used in HTL, decodes the url parameter:

https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.aemcomponents.dev%2Fcontent%2Fcore-components-examples%2Flibrary%2Fcore-content%2Fbutton.html&text=%C2%A9%20Core%20Components%20URI%20Link%20Encoding%20bug

linkManager
    .get("https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.aemcomponents.dev%2Fcontent%2Fcore-components-examples%2Flibrary%2Fcore-content%2Fbutton.html&text=%C2%A9%20Core%20Components%20URI%20Link%20Encoding%20bug")
    .withLinkTarget("_blank")
    .build()
    .getURL()

leads to the following Link:

https://twitter.com/intent/tweet?url=https://www.aemcomponents.dev/content/core-components-examples/library/core-content/button.html&text=%C2%A9%20Core%20Components%20URI%20Link%20Encoding%20bug

instead of:

https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.aemcomponents.dev%2Fcontent%2Fcore-components-examples%2Flibrary%2Fcore-content%2Fbutton.html&text=%C2%A9%20Core%20Components%20URI%20Link%20Encoding%20bug

Expected behavior/code Encoded URL parameters, shouldn't be decoded, in all cases.

Environment

Possible Solution LinkUtil should be fixed: https://github.com/adobe/aem-core-wcm-components/blob/3d55a142fdca4cea36a7459d3ed1ae5008da3666/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkUtil.java#L54

Roman-Skripka commented 1 year ago

We experience the same issue with 2.22.12, decoding in LinkBuilder and then encoding in default path processor breaks %26 (ampersand) param value in the link.