[MGNLSTK-740] Allow Resource.getLink() to support "Relative References" in external links Created: 30/Jan/11  Updated: 04/Nov/15  Resolved: 04/Nov/15

Status: Closed
Project: Magnolia Standard Templating Kit (closed)
Component/s: base system
Affects Version/s: 1.3.5, 1.4.2
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Brad Kazazes Assignee: Philipp Bärfuss
Resolution: Won't Do Votes: 0
Labels: css, js, references, relative, resources
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

A common problem I've found when building websites is when a site is made up of a combination of http and https pages and also require the use of a common external resource. One example of this, which is becoming more popular these days, is the use of the Google hosted JQuery library, http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js. The main problem is when browsers (mainly IE) continuously display errors when attempting to accessing unsecured resouces in secured pages. While the external resource could be changed to "https", this takes out the benefits of using the Google hosted solution.

After some investigation, I recently found out about "Relative References" which is described in the URI RFC, http://tools.ietf.org/html/rfc3986#section-4.2. This states that URI's can safely ignore the protocol handle of the URL which means we can access the JQuery, for example, as "//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js".

Please see the following site for a great description of this problem and how Relative References resolves it: http://encosia.com/2011/01/19/cripple-the-google-cdns-caching-with-a-single-character/

Our problem, however, is that I can't enter this type of link into the Theme, it is treated as an internal link where the context path is prepended. After some digging, I found this is due to the info.magnolia.module.templatingkit.resources.Resource.getLink() using the info.magnolia.link.LinkUtil.EXTERNAL_LINK_PATTERN to determine if the link is external or not; and this pattern doesn't allow for relative references.

The best solution would likely be to update the LinkUtil.EXTERNAL_LINK_PATTERN to allow for relative references; however I'm not sure what else depends on this pattern. If we can change the pattern, it should be a simple change to

public static final Pattern EXTERNAL_LINK_PATTERN = Pattern.compile("^(\\w*:?//|mailto:|javascript:).*");

although I haven't actually tested this.



 Comments   
Comment by Philipp Bärfuss [ 31/Jan/11 ]

Thanks for this insightful report. We are going to see if we can do something for this. For now you can apply the following solution:

  • create a subclass of Resource
  • add a class node-data to the link configuration to tell content2bean to use your custom class

Details about how this configuration mechanism works can be found in the content2bean chapter.

Comment by Michael Mühlebach [ 04/Nov/15 ]

Given the thousands of other issues we have open that are more highly requested, we won't be able to address this issue in the foreseeable future. Instead we will focus on issues with a higher impact, and more votes.
Thanks for taking the time to raise this issue. As you are no doubt aware this issue has been on our backlog for some time now with very little movement.
I'm going to close this to set expectations so the issue doesn't stay open for years with few updates. If the issue is still relevant please feel free to reopen it or create a new issue.

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