Skip to content

fix(codescanner): strip URLs before scanning to prevent false positives#30

Merged
BigMichi1 merged 1 commit into
mainfrom
fix/url-false-positives
May 15, 2026
Merged

fix(codescanner): strip URLs before scanning to prevent false positives#30
BigMichi1 merged 1 commit into
mainfrom
fix/url-false-positives

Conversation

@BigMichi1
Copy link
Copy Markdown
Owner

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, and jasoncharlesmiller matched the code regex (12–16 uppercase alphanumeric characters), producing false positive codes.

Example: https://www.twitch.tv/dungeonscrawlersDUNGEONSCRAWLERS (16 chars, matches regex).

Fix

Add a stripUrls helper that removes http:// and https:// URLs from the message text before code extraction. Applied in both scanMessageForCodes and extractCodesFromText.

Tests

Three new tests added to codeScanner.test.ts:

  • Does not extract Twitch username as code
  • Does not extract long URL path segments as codes
  • Strips http:// URLs as well as https://

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>
Copilot AI review requested due to automatic review settings May 15, 2026 09:56
@github-actions
Copy link
Copy Markdown

✅ Coverage Report

Metric Value
Current coverage 54.23% (930/1715)
Baseline coverage 54.17% (928/1713)
Result PASS

Changed Files

File Baseline Current Status
src/bot/handlers/codeScanner.test.ts SKIP (ignored)
src/bot/handlers/codeScanner.ts 24.24% 28.57% PASS

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stripUrls helper that removes https?://\S+ from text.
  • Apply URL stripping in both scanMessageForCodes and extractCodesFromText before 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.

@BigMichi1 BigMichi1 merged commit 4f63785 into main May 15, 2026
13 checks passed
@BigMichi1 BigMichi1 deleted the fix/url-false-positives branch May 15, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants