From 6853196b0bb8a07f6464db28d51bf912bf8d8e2a Mon Sep 17 00:00:00 2001 From: Satariall Date: Wed, 23 Jul 2014 13:15:29 +0400 Subject: [PATCH] FIX for detect relative protocol external links Some URL's with relative protocol, such as, `//example.com/whatever/` is not detects as external and ajaxify try to load http://inteernal.site/example.com/whatever, which is incorrect. These regulars expressions fix that and external links detect properly. --- ajaxify-html5.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ajaxify-html5.js b/ajaxify-html5.js index c232db7..07b87c6 100755 --- a/ajaxify-html5.js +++ b/ajaxify-html5.js @@ -49,11 +49,10 @@ url = $this.attr('href')||'', isInternalLink; - // Check link - isInternalLink = url.substring(0,rootUrl.length) === rootUrl || url.indexOf(':') === -1; - - // Ignore or Keep - return isInternalLink; + var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/); + if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) return false; + if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"), "") !== location.host) return false; + return true; }; // HTML Helper