[MGNLSTK-1214] stkTemplatingFunctions.getAssetLink() not consistently encoded Created: 24/Jul/13  Updated: 04/Dec/13  Resolved: 05/Sep/13

Status: Closed
Project: Magnolia Standard Templating Kit (closed)
Component/s: None
Affects Version/s: 2.0.10
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Adrien Berthou Assignee: Robert Šiška
Resolution: Obsolete Votes: 0
Labels: stk
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Magnolia 4.5.9


Issue Links:
causality
caused by MAGNOLIA-5290 Link referencing uploaded binary reso... Closed
relation
is related to MGNLSTK-1095 Escape values for rendering, don't es... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Date of First Response:

 Description   

stkTemplatingFunctions.getAssetLink(Node content, String nodeDataPrefix) returns an encoded url when the data has been "selected from the DMS" via the dialog.

However, it returns a non-encoded url when the data has been "uploaded" via the dialog.

Solution:
Encode the URL when it has been "uploaded" via the dialog. See example below:

String nonEncodedUrlStringForAsset = "//localhost:8080/url/to/non/encoded/doc/my doc.pdf";
URI uri = new URI("http", nonEncodedUrlStringForAsset, null);
URL url = uri.toURL();


 Comments   
Comment by Adrien Berthou [ 24/Jul/13 ]

To reproduce the bug:
upload a file that has spaces in its name to the DMS.
upload that same file via an dialog upload field.

Then find out the value returned when the relevant method is called on the first file.
And compare with the value returned when the relevant method is called on the second file.

Comment by Ondrej Chytil [ 12/Aug/13 ]

Hi Adrien,

can you please specify your environment and possibly your encoding related settings? I just tried to reproduce the issue but both upload and DMS are returning properly encoded links.

Comment by Adrien Berthou [ 15/Aug/13 ]

Hi Ondrej,

Here is my environment:
Windows
Tomcat v6.0
Magnolia 4.5.9
STK 2.0.10

Where can I find my encoding related settings?

More info regarding this issue, try doing:

String firstAssetLink = stkTemplatingFunctions.getAssetLink(nodeOne, "pdf");
String secondAssetLink = stkTemplatingFunctions.getAssetLink(nodeTwo, "pdf");
log.info("firstAssetLink : " + firstAssetLink );
log.info("secondAssetLink : " + secondAssetLink );

Again, try this with a file having a space in its name. nodeOne's pdf having been uploaded & nodeTwo's pdf beeing in the DMS. You should then see the difference in the URLs.
To fix this I simply added this for all cases (if the url is already correct this will not affect it):

assetLink = URLDecoder.decode(assetLink, "UTF-8");
Comment by Robert Šiška [ 05/Sep/13 ]

Fixed by MAGNOLIA-5290.

Generated at Mon Feb 12 07:34:27 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.