diff --git a/lua/express/misc/path.lua b/lua/express/misc/path.lua index fb25937..d385298 100644 --- a/lua/express/misc/path.lua +++ b/lua/express/misc/path.lua @@ -9,29 +9,29 @@ local string_split = require("express.utils").string_split -- (so also no leading and trailing slashes - it does not distinguish -- relative and absolute paths) local normalizeArray = function(parts, allowAboveRoot) - local res = {} - for i = 1, #parts do - local p = parts[i] - - -- ignore empty parts - if not p or p == "." then - goto continue - end - - if p == ".." then - if #res > 0 and res[#res] ~= ".." then - table.remove(res) - elseif allowAboveRoot then - table.insert(res, "..") - end - else - table.insert(res, p) - end - - ::continue:: - end - - return res + local res = {} + for i = 1, #parts do + repeat + local p = parts[i] + + -- ignore empty parts + if not p or p == "." then + break + end + + if p == ".." then + if #res > 0 and res[#res] ~= ".." then + table.remove(res) + elseif allowAboveRoot then + table.insert(res, "..") + end + else + table.insert(res, p) + end + until true + end + + return res end -- path.normalize(path) @@ -84,19 +84,19 @@ local function resolve(...) local resolvedAbsolute = false for i = select("#", ...), 0, -1 do - local path = (i >= 1) and select(i, ...) or full( arg[0] ) - - -- Skip empty and invalid entries - if type(path) ~= "string" then - error("Arguments to path.resolve must be strings") - elseif not path then - goto continue - end - - resolvedPath = path .. "/" .. resolvedPath - resolvedAbsolute = path:sub(1, 1) == "/" + repeat + local path = (i >= 1) and select(i, ...) or full( arg[0] ) + + -- Skip empty and invalid entries + if type(path) ~= "string" then + error("Arguments to path.resolve must be strings") + elseif not path then + break + end - ::continue:: + resolvedPath = path .. "/" .. resolvedPath + resolvedAbsolute = path:sub(1, 1) == "/" + until true end -- At this point the path should be resolved to a full absolute path, but diff --git a/lua/express/router/init.lua b/lua/express/router/init.lua index 64eaa06..a61bf4c 100644 --- a/lua/express/router/init.lua +++ b/lua/express/router/init.lua @@ -167,43 +167,43 @@ function ROUTER_MT:handle(req, res, out) -- find next matching layer local layer, match, route while match ~= true and idx <= #stack do - layer = stack[idx] - idx = idx + 1 - match = matchLayer(layer, path) -- bool or err str - route = layer.route - - if type(match) ~= "boolean" then - layerError = layerError or match - end - - if match ~= true then - goto continue - end - - if not route then - goto continue - end - - -- routes do not match with a pending error - if layerError then - match = false - goto continue - end - - local method = req.method - local has_method = route:_handles_method(method) - - -- build up automatic options response - -- if not has_method and method == "OPTIONS" then - -- appendMethods(options, route:_options()) - -- end - - -- don't even bother matching route - if not has_method and method ~= "HEAD" then - match = false - end - - ::continue:: + repeat + layer = stack[idx] + idx = idx + 1 + match = matchLayer(layer, path) -- bool or err str + route = layer.route + + if type(match) ~= "boolean" then + layerError = layerError or match + end + + if match ~= true then + break + end + + if not route then + break + end + + -- routes do not match with a pending error + if layerError then + match = false + break + end + + local method = req.method + local has_method = route:_handles_method(method) + + -- build up automatic options response + -- if not has_method and method == "OPTIONS" then + -- appendMethods(options, route:_options()) + -- end + + -- don't even bother matching route + if not has_method and method ~= "HEAD" then + match = false + end + until true end if match ~= true then