In a SharePoint MVC hosted app the ‘spcontext.js’ files has a piece of code that will append each hyperlink with the ‘SPHostUrl’ attribute.

Great….

But I ran into the fact that the script was crashing for some reason…
I added this piece

if (authority == null)
return false;

Into the file so it does not do an UpperCase on the next line because of the fact that the object is null

Modified function:

// Appends SPHostUrl as query string to all the links which point to current domain.
function appendSPHostUrlToLinks(spHostUrl, currentAuthority) {
$(“a”)
.filter(function () {
var authority = getAuthorityFromUrl(this.href);

//ADDED PIECE OF CODE
if (authority == null)

return false;

if (!authority && /^#|:/.test(this.href)) {
// Filters out anchors and urls with other unsupported protocols.
return false;
}
return authority.toUpperCase() == currentAuthority;
})
.each(function () {
if (!getSPHostUrlFromQueryString(this.search)) {
if (this.search.length > 0) {
this.search += “&” + SPHostUrlKey + “=” + spHostUrl;
}
else {
this.search = “?” + SPHostUrlKey + “=” + spHostUrl;
}
}
});
}