West Midlands | 26 March SDC | Iswat Bello | Sprint 1 | Purple Forest/bug report/Hashtag link doesn't work#211
Conversation
Restrict hashtag parsing in bloom.mjs from /\B#[^#]+/g to /\B#[\w]+/g so hashtags include only letters/digits/underscore and exclude punctuation or spaces.
nedssoft
left a comment
There was a problem hiding this comment.
This is a beautiful piece of debugging, Iswat. 👏 Tracing the empty page back to the over-encoded URL (%2520), realising [^#]+ was greedily swallowing the trailing space and punctuation, then switching to \w+ so it stops at the first non-word character — that's a really clear grasp of how regex character classes work. Verified cleanly, too. Lovely work — nothing to change here.
Thank you so much @nedssoft, for the feedback. |
Learners, PR Template
Self checklist
Changelist
This PR fixes a bug where hashtags located in the middle of a sentence were incorrectly linked because the application captured trailing spaces and punctuation as part of the hashtag name.
1. Reproduction Steps
To confirm the bug, I performed the following:
Swiz: "Let's get some #SwizBiz love!!"http://localhost:3000/hashtag/SwizBiz%2520love!!.2. The Problem
Hashtags located in the middle of a sentence were being "over-captured." Because the link included spaces and punctuation, the backend could not find a match in the database, resulting in an empty results page.
3. The Discovery
I investigated
frontend/components/bloom.mjsand found the_formatHashtagsfunction./\B#[^#]+/g.[^#]+part tells the browser to "capture every character that is NOT a hash." Since spaces and exclamation marks are not hashes, the browser kept grabbing them until the end of the string.4. The Fix
I updated the Regex pattern in
frontend/components/bloom.mjsto:/\B#\w+/g5. The Logic
By switching to
\w+, the Regex is now restricted to "Word Characters" (letters, numbers, and underscores).6. Verification
After the fix, I returned to the timeline and clicked the same link.
#SwizBiz./hashtag/SwizBiz.