Fix the HttpRouter to handle overlapping of the routes #359
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.
This PR should fix #355 and can be resumed in the following steps:
HttpRouter
to handle overlapping between routes with wildcard correctly.SwifterTestHttpRouter
in theSwifteriOSTests
.The current
findHandler(_:, ..)
function was taking only one path once a match was found and sometimes incorrectly, let's see the two routes proposed in the issue:a/b
a/:id/c
If we see the following tree generated by the two routes above it should look like the following:
GET | a / \ :id b / c
The previous
findHandler(_:, ..)
algorithm was traversing the path recursively and returning if a match was found but the way it was implemented makes really hard to take advantage of the recursive search to continue searching in case of went through a path incorrectly.In the refactored algorithm I didn't return only a match, nevertheless, all the possible matches in the Tree kept in an array and handling the incorrect path without return anything directly.
There are several updates to the previous algorithms in terms of refactoring but two are very important:
generator
.generator
doesn't have more nodes and the current node neither and that means it's a match in the tree.Happy to discuss more or any doubt in the refactoring. Happy review!