kemalcr / kemal

Fast, Effective, Simple Web Framework
https://kemalcr.com
MIT License
3.65k stars 189 forks source link

fixed executing filters when before and after is defined at the same time #612

Closed mamantoha closed 3 years ago

mamantoha commented 3 years ago

Code to reproduce:

require "kemal"

before_all do |env|
  puts "BEFORE <"
end

after_all  do |env|
  puts "> AFTER"
end

get "/" do
  "Hello World!"
end

Kemal.run

after request will never be executed.

Not sure what going on here. But the origin of the issue is in radix shard. It does not properly handle paths without trailing /.

require "radix"

tree = Radix::Tree(Symbol).new

tree.add "after/ALL/*", :after
tree.add "before/ALL/*", :before

pp tree.find "after/ALL/*"
pp tree.find "before/ALL/*"

Output

#<Radix::Result(Symbol):0x7fbf3bb8bf00 @key=nil, @params={}, @payload=:after>
#<Radix::Result(Symbol):0x7fbf3bb8bcf0 @key=nil, @params={}, @payload=nil>