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
746 stars 753 forks source link

Download component doesn't work when + character is in filename #2862

Open juw177 opened 2 months ago

juw177 commented 2 months ago
  1. Upload a file to DAM with a + character in the file name
  2. Use this in the Download component
  3. The link comes up as broken
ky940819 commented 1 month ago

For reference.

This issue is caused by line 180 here:

https://github.com/adobe/aem-core-wcm-components/blob/d2a7b02405db241fadbad02a4878f8770b36e246/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/link/LinkBuilderImpl.java#L177-L188

The path is decoded by the LinkBuilder. In your case the + symbol is decoded into a space. Later, the path is re-encoded and the space is converted into %20 (as would be proper for a space).

The addition of this pre-decoding was done here: https://github.com/adobe/aem-core-wcm-components/commit/87a8c2a1879ddd2ced81844a7afed8b59e448984

If I understand the change correctly, then the purpose was to handle situations where the link may come from author-input data and may already be encoded (i.e. a button where an author copy/pasted a link - which is reasonable for them to do). If the URL were not to be decoded, then it would end up double-encoded.

Ideally this wouldn't happen when the link is coming from a resource path (i.e. a page, asset, etc) because we know it's not already encoded.

This specific case could probably be eliminated by using a URL decoding method that adheres to RFC2396. The java.net.URLDecoder utility states This class contains static methods for decoding a String from the application/x-www-form-urlencoded MIME format (see https://docs.oracle.com/javase/8/docs/api/java/net/URLDecoder.html).