After emmiting new message to client and receiving it in the client side I'm passing it trough function which determines hyperlinks and makes it clickable. The problem is that if string contains link like this this is the link http://linktosomwhere.com?ref=myname to somewhere
it parses the link wrong and makes it like this: this is the link <a...>http://linktosomwhere.com</a> ?ref=myname to somewhere
. So it breaks the link adding the space where it shouldn't be. As I mentioned before, everything is going on on client side with this function:
function linkify(inputText) {
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = inputText.replace(replacePattern1, '<a href="$1" rel="nofollow" target="_blank">$1</a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a rel="nofollow" href="http://$2" target="_blank">$2</a>');
//Change email addresses to mailto:: links.
replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
return replacedText;
}
console.log(linkify('this is the link http://linktosomwhere.com?ref=myname to somewhere'));