Open
Conversation
Fixes #271. This is a breaking change
recognize to take params as kwarg
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.
Fixes #271.
Router#recognizewas silently ignoring themethod:kwarg when called without an explicitparamshash, returning the verb as GET for POST routes and often picking the wrong route.Root cause: the old signature
recognize(env, params = {}, options = {})absorbedmethod: :postinto the positionalparamsargument, leavingoptionsempty when it was handed toRack::MockRequest.env_for.Fixes the bug by moving to an explicit kwargs signature:
I also renamed
envtotargetto reflect that the argument accepts a path, a route name, or a Rack env hash.This is a breaking change, so will need to be for hanami-router v3. It seems like a good time to fix this "the right way" instead of making a backward-compatible fix that we'd have to continue to maintain. This new approach is much more explicit.
There's a slight behavior change in that we double splat the keyword args, so they're converted to symbols, so e.g. "HTTP_AUTHORIZATION" will get converted to a symbol, which Rack drops. There's a very simple fix though: callers who need this can build the env explicitly via Rack::MockRequest.env_for and pass it in as the target.
I worked with Claude Code to get this fixed, refactored, and all of the documentation updated.