Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: Naming of routes works wrong #2685

Closed
3 tasks done
Antonov-guap opened this issue Oct 20, 2023 · 4 comments · Fixed by #2686
Closed
3 tasks done

🐛 [Bug]: Naming of routes works wrong #2685

Antonov-guap opened this issue Oct 20, 2023 · 4 comments · Fixed by #2686
Assignees

Comments

@Antonov-guap
Copy link

Antonov-guap commented Oct 20, 2023

Bug Description

Naming of routes with the same path and different methods works wrong.
All routes with the same path are replaced with new given name.

How to Reproduce

Steps to reproduce the behavior:

  1. Create new app:
app := fiber.New()
app.Get("/users", nil).Name("get-users")
app.Post("/users", nil).Name("add-user")
  1. Try to get route by name:
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
location, err := c.GetRouteURL("get-users", fiber.Map{})
  1. Check the result:
fmt.Println("location:", location)
fmt.Println("err:", err)
  1. Actual result:
location: 
err: <nil>

Expected Behavior

Expected that path will be "/users" with no error:

location: /users
err: <nil>

Fiber Version

v2.50.0

Code Snippet (optional)

package main

import (
	"fmt"

	"github.com/gofiber/fiber/v2"
	"github.com/valyala/fasthttp"
)

func main() {
	app := fiber.New()
	app.Get("/users", nil).Name("get-users")
	app.Post("/users", nil).Name("add-user")

	c := app.AcquireCtx(&fasthttp.RequestCtx{})
	defer app.ReleaseCtx(c)
	location, err := c.GetRouteURL("get-users", fiber.Map{})

	fmt.Println("location:", location)
	fmt.Println("err:", err)

	getUsers := app.GetRoute("get-users")
	addUser := app.GetRoute("add-user")

	fmt.Println("get-users:", getUsers.Method, getUsers.Path)
	fmt.Println("add-user:", addUser.Method, addUser.Path)
}

// Output: 
// location: 
// err: <nil>
// get-users:  
// add-user: GET /users

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@welcome
Copy link

welcome bot commented Oct 20, 2023

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@trapcodeio
Copy link

I think this is related to #2671

@Antonov-guap
Copy link
Author

Antonov-guap commented Oct 20, 2023

yes, related, but issue #2671 has test (i saw it). And this test is also has problems. It adds some name, after it asserts, then again add name -> assert. But if you add all the names before, and then assert all, you will get unpredictable result, cos name adding affect all names previously added.

@Antonov-guap
Copy link
Author

Antonov-guap commented Oct 20, 2023

and also, I didn't make an issue, but when you mount app as subApp, then mount also drops names of routes (when listen started).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants