Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions lua/express/misc/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
74 changes: 37 additions & 37 deletions lua/express/router/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down