A user reported a bug where text following the string “http” or “https” fails to render if a full URL is posted nearby. anon42064797 provided an example showing how the parser incorrectly consumes the text. cpradio shared a screenshot to illustrate the issue, and sam praised the catch, identifying the source as the autolink_dialect.js file. rhulse volunteered to investigate the JavaScript code. Initial analysis suggested the issue might stem from the start token or non-greedy regex matching. Mittineague and riking noted that character counts and spaceOrTagBoundary settings might be factors. Ultimately, chapel identified that the global (g) and multiline (m) flags in the existing regex were causing the problem. They proposed a corrected regex pattern and submitted a pull request to fix the issue: https://github.com/discourse/discourse/pull/3175.
Does this bug come from ruby code or external library? If it’s ruby and there is a bug open in the tracker can I have link? I could have a look into it.
I had a think about what the user posts and expects from their input, and what is likely to be valid. Anyone posting a valid link is always going to include http(s): with the colon. Always. Anyone leaving that off the link is going to put a dot after the www. Always. Well they are if they want to work if it is cut and pasted.
So based on that I would first suggest (before diving into the really hard regexp) a simple change to the tokens that you look for (lines 24-25). Very roughly:
Okay, through some trial and error and some looking around I found a regex that passes this edge case and seems to be simple enough but strong enough as well.