Skip to content

Commit

Permalink
empty URL shouldn't be possible, move check to an assert
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Sep 16, 2024
1 parent dadc4f7 commit 7aade76
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ pub fn Part(comptime A: type) type {
}

fn getRoute(comptime A: type, root: *const Part(A), url: []const u8, params: *Params) ?A {
if (url.len == 0 or (url.len == 1 and url[0] == '/')) {
std.debug.assert(url.len != 0);
if (url.len == 1 and url[0] == '/') {
return root.action;
}

Expand Down Expand Up @@ -478,17 +479,12 @@ test "route: root" {

router.get("/", testRoute1, .{});
router.put("/", testRoute2, .{});
router.post("", testRoute3, .{});
router.all("/all", testRoute4, .{});

const urls = .{ "/", "/other", "/all" };
try t.expectEqual(&testRoute1, router.route(httpz.Method.GET, "", &params).?.action);
try t.expectEqual(&testRoute2, router.route(httpz.Method.PUT, "", &params).?.action);
try t.expectEqual(&testRoute3, router.route(httpz.Method.POST, "", &params).?.action);

try t.expectEqual(&testRoute1, router.route(httpz.Method.GET, urls[0], &params).?.action);
try t.expectEqual(&testRoute2, router.route(httpz.Method.PUT, urls[0], &params).?.action);
try t.expectEqual(&testRoute3, router.route(httpz.Method.POST, urls[0], &params).?.action);

try t.expectEqual(null, router.route(httpz.Method.GET, urls[1], &params));
try t.expectEqual(null, router.route(httpz.Method.DELETE, urls[0], &params));
Expand Down

0 comments on commit 7aade76

Please sign in to comment.