[MGNLSTK-551] External links do not allow any other protocol than http Created: 23/Dec/09  Updated: 23/Jan/13  Resolved: 27/Oct/10

Status: Closed
Project: Magnolia Standard Templating Kit (closed)
Component/s: None
Affects Version/s: 1.1.2
Fix Version/s: 1.3.6, 1.4

Type: Bug Priority: Major
Reporter: Andreas Weder (MP) (Inactive) Assignee: Ondrej Chytil
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

any


Attachments: Text File MGNLSTK-551.patch    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Date of First Response:

 Description   

If you enter any external link with a protocol different from http, the string "http://" is prepended to it.

This is due to STKUtil only checking of a string prefix of "http://", but fails to detect other protocols such as https. I've attached a new implementation of both affected STKUtil methods. I couldn't create an actual patch in the given timeframe easily, sorry.

The following two methods accept any protocol, but still prepend "http://" in case none is given:

public static String getExternalLink(Content content, String linkNodeName){
String externalLink = content.getNodeData(linkNodeName).getString();

if(!externalLink.contains("://"))

{ externalLink = "http://"+externalLink; }

return externalLink;
}

public static String getExternalLinkTitle(Content content, String linkNodeName, String linkTitleNodeName){
String linkTitle = content.getNodeData(linkTitleNodeName).getString();
if(StringUtils.isNotEmpty(linkTitle))

{ return linkTitle; }

String externalLink = content.getNodeData(linkNodeName).getString();
int idx = externalLink.indexOf("://");
if(idx != -1){
if (externalLink.length() > idx+3)

{ externalLink = externalLink.substring(idx+3); }

else

{ externalLink = ""; }

}
return externalLink;
}



 Comments   
Comment by Magnolia International [ 26/Oct/10 ]

Here's a patch to fix this; please review and apply.

Comment by Philipp Bärfuss [ 26/Oct/10 ]

Seams as if this slipped through. Just added it the maintenance mindmap.

Comment by Jan Haderka [ 27/Oct/10 ]

Patch should be improved. getExternalLinkTitle() can just delegate to the getExternalLink() in case title is empty instead of executing exactly same C&P code.

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