Skip to content

Commit 620f51c

Browse files
authored
Merge pull request #368 from QualityUnit/multiple_emails_in_url
fix autolinking of URL with multiple email addresses in query string
2 parents 5e5ba9d + 6478ae8 commit 620f51c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/autolinker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,8 @@ export default class Autolinker { // NOTE: must be 'export default' here for UM
745745
private compactMatches( matches: Match[] ) {
746746
// First, the matches need to be sorted in order of offset
747747
matches.sort( function( a, b ) { return a.getOffset() - b.getOffset(); } );
748-
749-
for( let i = 0; i < matches.length - 1; i++ ) {
748+
let i = 0;
749+
while(i < matches.length - 1) {
750750
let match = matches[ i ],
751751
offset = match.getOffset(),
752752
matchedTextLength = match.getMatchedText().length,
@@ -763,8 +763,10 @@ export default class Autolinker { // NOTE: must be 'export default' here for UM
763763
// Remove subsequent matches that overlap with the current match
764764
if( matches[ i + 1 ].getOffset() < endIdx ) {
765765
matches.splice( i + 1, 1 );
766+
continue;
766767
}
767768
}
769+
i++;
768770
}
769771

770772
return matches;

tests/autolinker-url.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,4 +1073,13 @@ describe( "Autolinker Url Matching -", () => {
10731073

10741074
} );
10751075

1076+
describe( "emails in URL", function() {
1077+
it( "should autolink a url with multiple email in the query string", function() {
1078+
const result = autolinker.link("https://example.com/api/path?apikey={API_Key}&message=Test&[email protected]&department=someid123&subject=Some_Subject&[email protected]&is_html_message=Y");
1079+
1080+
expect( result ).toBe( '<a href="https://example.com/api/path?apikey={API_Key}&message=Test&[email protected]&department=someid123&subject=Some_Subject&[email protected]&is_html_message=Y">example.com/api/path?apikey={API_Key}&message=Test&[email protected]&department=someid123&subject=Some_Subject&[email protected]&is_html_message=Y</a>' );
1081+
} );
1082+
1083+
} );
1084+
10761085
} );

0 commit comments

Comments
 (0)