Skip to content

route: return route on Queries parameter error instead of nil - #822

Closed
00200200 wants to merge 1 commit into
gorilla:mainfrom
00200200:fix-queries-nil-route
Closed

00200200 wants to merge 1 commit into
gorilla:mainfrom
00200200:fix-queries-nil-route

Conversation

@00200200

Copy link
Copy Markdown

Summary

When Route.Queries receives an odd number of parameters, it previously set r.err and returned nil. Because callers use fluent builder chaining on *Route (such as r.Queries(...).Path(...).Handler(...) or checking r.Queries(...).GetError()), returning nil caused an immediate nil pointer dereference instead of preserving the error on the route.

This change:

  • Updates Route.Queries to return r when parameter validation fails, consistent with Headers, HeadersRegexp, and other route builder methods.
  • Guards Queries with if r.err == nil so pre-existing route errors are preserved without attempting redundant regexp additions.
  • Adds unit tests verifying that chaining on odd query parameters does not panic, the error is recorded on the route, and routes with errors do not match incoming requests.

@00200200

Copy link
Copy Markdown
Author

Closing, since this repository has not had any commits since mid-2024. Happy to reopen if it becomes active again.

@00200200 00200200 closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant