Fix too greedy TrackLink regex replacement. #2355
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there!
First, thank you for developing and maintaining listmonk - it's an awesome tool and very easy to use!
I implemented listmonk at my company a few weeks ago, and one recurring issue reported by the marketing team is that they sometimes cannot save tracked links.
Issue Description
After investigating, I found that the issue stems from the TrackLink regex replacement, which incorrectly matches more characters than intended. This results in template compilation errors like:
A minimal reproducible example is inserting two links in the same line:
This causes the campaign to fail rendering.

Root Cause
The issue occurs because the

@TrackLink
syntax regex matches too many characters, unintentionally breaking the DOM.As you can see here, the expression starts with the "https://" of the first link and ends with the second tracked link.
Different combinations of imgs and links in the same link can of course also trigger this issue.
Fix
I updated the regex to only match characters that are valid in a URL per RFC 3986, ensuring a clean stop after the URL.
Let me know if you'd like any adjustments. Thanks!