Skip to content

fix(router): guard Remove against deleting entry 0 on no-match - #3097

Open
simpleqt wants to merge 1 commit into
labstack:masterfrom
simpleqt:fix/router-remove-wrong-entry
Open

simpleqt wants to merge 1 commit into
labstack:masterfrom
simpleqt:fix/router-remove-wrong-entry

Conversation

@simpleqt

Copy link
Copy Markdown

The bug

DefaultRouter.Remove searched r.routes for the normalized path but Add stores the raw path. When they differ (e.g. e.GET("users", h) without a leading slash), rIndex stayed at 0 and r.routes[0] — a completely unrelated route — was silently deleted from the route listing while the dead entry remained.

Fix

Return nil when no matching entry is found instead of deleting r.routes[0] unconditionally.

rIndex defaulted to 0 and the delete executed unconditionally. When the
normalized lookup path didn't match any stored raw path (e.g. 'users'
stored without a leading slash), r.routes[0] was silently deleted while
the dead entry remained.
Copilot AI lite review requested due to automatic review settings September 14, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aldas

aldas commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

but where is the test-case?

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.71%. Comparing base (dcb05f0) to head (b0f3aba).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
router.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3097      +/-   ##
==========================================
+ Coverage   93.34%   95.71%   +2.36%     
==========================================
  Files          43       44       +1     
  Lines        4735     4036     -699     
==========================================
- Hits         4420     3863     -557     
+ Misses        192      173      -19     
+ Partials      123        0     -123     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants