gregjacobs / Autolinker.js

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
MIT License
1.48k stars 238 forks source link

URL with multiple email addresses in query string is not linked correctly #367

Closed martincivan closed 2 years ago

martincivan commented 2 years ago

URL with 2 email addresses in query string (e.g. https://example.com/api/path?apikey={API_Key}&message=Test&useridentifier=name.surname@subdomain.domain.com&department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y ) is not linked correctly.

Current result: <a href="https://example.com/api/path?apikey={API_Key}&message=Test&useridentifier=name.surname@subdomain.domain.com&department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y">example.com/api/path?apikey={API_Key}&message=Test&useridentifier=name.surname@subdomain.domain.com&department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y</a>department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y<a href="mailto:department=someid123&subject=Some_Subject&recipient=other.name@address.com">department=someid123&subject=Some_Subject&recipient=other.name@address.com</a>&is_html_message=Y

Expected result: <a href="https://example.com/api/path?apikey={API_Key}&message=Test&useridentifier=name.surname@subdomain.domain.com&department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y">example.com/api/path?apikey={API_Key}&message=Test&useridentifier=name.surname@subdomain.domain.com&department=someid123&subject=Some_Subject&recipient=other.name@address.com&is_html_message=Y</a>

The problem is https://github.com/gregjacobs/Autolinker.js/blob/master/src/autolinker.ts#L759 - here (and a few lines below) we are modifying the array we are iterating over. And therefore 2 subsequent matches that are overlapped by the first item are not removed properly.