Skip to content

[bug] Wrong http method when clean path over an invalid path #673

@pcabreus

Description

@pcabreus

Describe the bug
I was having an issue on my api calling a patch endpoint, that was never reach. Any patch call that I was making ended up on the get path of the same resource. By mistake I was making request to PATCH localhost//resources/item with two slashes.
I think mux tried to clean the url by removing the double slashes but the original method was changed by a GET so I was finally receiving a GET localhost/resources/item.

Versions

Go version: 1.17
package version: run git rev-parse HEAD inside the repo

Steps to Reproduce

  1. Create a route PATCH localhost/resources/item
  2. Create a route GET localhost/resources/item
  3. Create a handler for each route (Be sure to know when any of this handler is called)
  4. Run the server and call the endpoint properly to check if working as expected
  5. Then call the patch endpoint with PATCH localhost//resources/item adding some extra slashes
  6. The Get endpoint is called

Expected behavior
That is a not clean behavior. For my point of view could be any of:

  1. Not found because the path it not valid
  2. Preserve the method after the path cleaning.

Code Snippets

A minimum viable code snippet can be useful! (use backticks to format it).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions