Uploaded image for project: 'Magnolia Standard Templating Kit (closed)'
  1. Magnolia Standard Templating Kit (closed)
  2. MGNLSTK-740

Allow Resource.getLink() to support "Relative References" in external links

XMLWordPrintable

      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.

        Acceptance criteria

              pbaerfuss Philipp Bärfuss
              bkazazes Brad Kazazes
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: