Skip to content

Commit 00c344a

Browse files
authored
Merge pull request #24 from horan-geeker/develop
fix: router
2 parents 5f86f96 + eb1d8d5 commit 00c344a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/router.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ local function generate_route(root_tree, route_uri, route_info)
116116
local sub_uris = split_uri(route_uri)
117117
local current_tree = root_tree
118118
for _, uri in ipairs(sub_uris) do
119-
local node = current_tree:find_child_by_key(uri)
119+
local node = current_tree:find_child_with_pattern(uri)
120120
if node == nil then
121121
node = trie:new()
122122
current_tree:append_child(uri, node)

lib/trie.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,20 @@ function _M:find_child_by_key(key)
2525
end
2626
return self.children[key]
2727
end
28+
29+
30+
function _M:find_child_with_pattern(key)
31+
if string.char(string.byte(key)) == '{' then
32+
for child_key, child in pairs(self.children) do
33+
if string.char(string.byte(child_key)) == '{' then
34+
return child, key
35+
end
36+
end
37+
end
38+
if not self.children[key] then
39+
return nil
40+
end
41+
return self.children[key]
42+
end
43+
2844
return _M

0 commit comments

Comments
 (0)