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

Routes with different variables on the same level do not work #53

Open
ahx opened this issue Jun 11, 2024 · 5 comments
Open

Routes with different variables on the same level do not work #53

ahx opened this issue Jun 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@ahx
Copy link

ahx commented Jun 11, 2024

Hi,

I noticed that when adding routes with dynamic and static fields on the same level the trie get's confused:

	router = Lennarb::RouteNode.new
	router.add_route(['foo', ':foo'], 'GET', proc { 'foo' })
	router.add_route(%w[foo special], 'GET', proc { 'special' })
	router.add_route(['foo', ':id', 'bar'], 'GET', proc { 'bar' })

	_, params = router.match_route(%w[foo 23], 'GET')
	assert_equal({ foo: '23' }, params) # Fails because params are {:id=>"23"} instead of {:foo=>"23"}

I have added a PR to illustrate this.

This is the same problem hanami-router has.

Thanks for publishing this gem. I think it's super nice.

@ahx ahx changed the title Conflicting routes Routes with diffent variables on the same level do not work Jun 11, 2024
@ahx ahx changed the title Routes with diffent variables on the same level do not work Routes with different variables on the same level do not work Jun 11, 2024
@aristotelesbr
Copy link
Owner

Hi @ahx! Thank you for reporting this issue. I really appreciate your feedback and the PR you submitted to illustrate the problem. I'll take a look and try to fix the trie behavior. Any suggestions? 😄

@aristotelesbr aristotelesbr added the bug Something isn't working label Jun 14, 2024
@ahx
Copy link
Author

ahx commented Jun 14, 2024

Hi. I did not find a way to solve this so far. It’s not an easily solved problem. Others have struggled with this before and failed.

@aristotelesbr
Copy link
Owner

Hi @ahx,

I'm not entirely sure, but this #54 might address the issue you reported here.

Let me know if you get a chance to test it! 🙃

@ahx
Copy link
Author

ahx commented Sep 21, 2024

Hey @aristotelesbr. Thanks for looking into that. The test is green, so I think you solved the issue. Nice work!

@ahx
Copy link
Author

ahx commented Sep 21, 2024

Something not related to this issue: The reason I am interested in all this is, because I am looking for a small, fast routing library to use in openapi_first. I wish we would have a de-facto default library/gem to use in Ruby where people can build their own micro/midi/macro framework on top off. Lennarb's route_node.rb looks like a good candidate for that. (toot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants