Chat Linking Bug

Subscribe to Chat Linking Bug 1 post

avatar for skyboy skyboy 6261 posts
Flag Post

when a link to kong in chat lacks a protocol (e.g., http://) the link will still be created and not lead to the desired page.

the fix is relatively simple:

// holodeck.js ::addMessageFilters
kong_url_matcher = new RegExp("\\b((https?://|)www\\." + kong_domain + "(?:\/\[^\\s\"]*)*\\b/?)", 'i') // protocol matching group(index 2): will contain protocol or empty string ("")


    // Link Kongregate URLs
    this.addIncomingMessageFilter(function(message, nextFunction) {
      nextFunction(
        message.gsub(kong_url_matcher, function(match) {
          return '<a href="' + (match[2] ? '' : location.protocol + '//') + match[0] + '" target="_blank">' + match[0] + '</a>'; // add current page protocol when no protocol present
        }),
        nextFunction);
    });