-
Notifications
You must be signed in to change notification settings - Fork 67
fix: sort_route uses vars count as tiebreaker to match max vars #158
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,6 +205,9 @@ local mt = { __index = _M, __gc = gc_free } | |
|
|
||
| local function sort_route(route_a, route_b) | ||
| if route_a.priority == route_b.priority then | ||
| if #route_a.path_org == #route_b.path_org then | ||
| return (route_a.vars_len or 0) > (route_b.vars_len or 0) | ||
| end | ||
| return #route_a.path_org > #route_b.path_org | ||
| end | ||
| return (route_a.priority or 0) > (route_b.priority or 0) | ||
|
|
@@ -438,6 +441,7 @@ local function common_route_data(path, route, route_opts, global_opts) | |
| error("failed to handle expression: " .. err, 2) | ||
| end | ||
| route_opts.vars = route_expr | ||
| route_opts.vars_len = #route.vars | ||
| end | ||
|
Comment on lines
434
to
445
|
||
|
|
||
| local hosts = route.hosts | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tiebreaker is triggered when
#route_a.path_org == #route_b.path_org, which is broader than the PR’s stated intent (“same priority and uri”). Different paths with the same length (possible in the sameroutesbucket for param/prefix matches) would now be reordered byvars_len, changing routing precedence beyond identical URIs. If the intent is only to break ties for identical paths, consider checkingroute_a.path_org == route_b.path_org(string equality) before comparingvars_len, and otherwise keep the existing ordering rules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed