fix(codescanner): strip URLs before scanning to prevent false positives#30
Merged
Conversation
Twitch URLs (e.g. https://www.twitch.tv/dungeonscrawlers) were being uppercased and their path segments matched as valid codes. Add a stripUrls helper that removes http/https URLs prior to code extraction, applied in both scanMessageForCodes and extractCodesFromText. Add three new tests covering Twitch username false positives and http URLs. Signed-off-by: Michael Cramer <michael@bigmichi1.de>
✅ Coverage Report
Changed Files
|
There was a problem hiding this comment.
Pull request overview
Adds URL stripping prior to code regex matching to prevent Twitch (and other) URL path segments from being falsely detected as redemption codes.
Changes:
- Introduce
stripUrlshelper that removeshttps?://\S+from text. - Apply URL stripping in both
scanMessageForCodesandextractCodesFromTextbefore uppercasing. - Add three tests covering Twitch usernames, long URL path segments, and
http://URLs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/bot/handlers/codeScanner.ts | Adds stripUrls helper and applies it in both scanning entry points. |
| src/bot/handlers/codeScanner.test.ts | Adds tests verifying URL contents are not extracted as codes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When scanning Discord messages for codes, Twitch URLs were being included in the text before matching. After uppercasing, URL path segments like
dungeonscrawlers,playonwordsstudios, andjasoncharlesmillermatched the code regex (12–16 uppercase alphanumeric characters), producing false positive codes.Example:
https://www.twitch.tv/dungeonscrawlers→DUNGEONSCRAWLERS(16 chars, matches regex).Fix
Add a
stripUrlshelper that removeshttp://andhttps://URLs from the message text before code extraction. Applied in bothscanMessageForCodesandextractCodesFromText.Tests
Three new tests added to
codeScanner.test.ts:http://URLs as well ashttps://