From 6478ae8e7eef456c409654cc89beab1905c1660b Mon Sep 17 00:00:00 2001 From: Martin Civan Date: Sat, 8 Jan 2022 19:39:50 +0100 Subject: [PATCH] fix autolinking of URL with multiple email addresses in query string --- src/autolinker.ts | 6 ++++-- tests/autolinker-url.spec.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/autolinker.ts b/src/autolinker.ts index 41697b32..26069ea1 100644 --- a/src/autolinker.ts +++ b/src/autolinker.ts @@ -745,8 +745,8 @@ export default class Autolinker { // NOTE: must be 'export default' here for UM private compactMatches( matches: Match[] ) { // First, the matches need to be sorted in order of offset matches.sort( function( a, b ) { return a.getOffset() - b.getOffset(); } ); - - for( let i = 0; i < matches.length - 1; i++ ) { + let i = 0; + while(i < matches.length - 1) { let match = matches[ i ], offset = match.getOffset(), matchedTextLength = match.getMatchedText().length, @@ -763,8 +763,10 @@ export default class Autolinker { // NOTE: must be 'export default' here for UM // Remove subsequent matches that overlap with the current match if( matches[ i + 1 ].getOffset() < endIdx ) { matches.splice( i + 1, 1 ); + continue; } } + i++; } return matches; diff --git a/tests/autolinker-url.spec.ts b/tests/autolinker-url.spec.ts index 2920584e..fcc13a2b 100644 --- a/tests/autolinker-url.spec.ts +++ b/tests/autolinker-url.spec.ts @@ -1073,4 +1073,13 @@ describe( "Autolinker Url Matching -", () => { } ); + describe( "emails in URL", function() { + it( "should autolink a url with multiple email in the query string", function() { + const result = autolinker.link("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"); + + expect( result ).toBe( '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' ); + } ); + + } ); + } );