Skip to content

Commit

Permalink
tests(router/atc): ensure request path is normalized before extractin…
Browse files Browse the repository at this point in the history
…g segments from it (#12407)

KAG-3351
  • Loading branch information
chronolaw committed Feb 26, 2024
1 parent ffabedd commit 1252b7f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/01-unit/08-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5544,6 +5544,38 @@ do
assert.falsy(match_t)
end)

it("exec() should normalize uri with http.segments.*", function()
local use_case = {
{
service = service,
route = {
id = "e8fb37f1-102d-461e-9c51-6608a6bb8101",
expression = [[http.path.segments.0 == "foo" && http.path.segments.1 == "bar" && http.path.segments.2 == "baz" && ]] ..
[[http.path.segments.len == 3]],
priority = 100,
},
},
}

local router = assert(new_router(use_case))

local ctx = {}
local _ngx = mock_ngx("GET", "/foo/bar/baz", { a = "1", })
router._set_ngx(_ngx)

local match_t = router:exec(ctx)
assert.truthy(match_t)
assert.same(use_case[1].route, match_t.route)

local ctx = {}
local _ngx = mock_ngx("GET", "/foo//bar///baz//", { a = "1", })
router._set_ngx(_ngx)

local match_t = router:exec(ctx)
assert.truthy(match_t)
assert.same(use_case[1].route, match_t.route)
end)

it("exec() should hit cache with http.segments.*", function()
local use_case = {
{
Expand Down

0 comments on commit 1252b7f

Please sign in to comment.