-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid executing filters even if prefix matched with other namespace #1253
Conversation
31d796a
to
f458b71
Compare
Thank you @namusyaka, I'm happy to merge this but will wait for @mwpastore's seal of approval ;) |
Any progress on this? |
@mwpastore Could you check about this? |
Hi @namusyaka, I pinged you on the Slack about this, but I guess you didn't see it. I'm getting hung up on this because I don't really understand the solution. Can you help me understand the why and how? That being said, my review is superfluous if it solves the problem. |
@mwpastore @zzak Sorry for the late reply. The sinatra namespace is prefixed to verb and filter methods (see https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/namespace.rb#L232) by using original methods of indivisual namespaces. Please take a look at these lines. require 'mustermann'
# These vars are prefix of namespace.
foo = Mustermann.new('/foo')
foo_bar = Mustermann.new('/foo-bar')
# current pattern
regexp = Mustermann.new(/.*/)
p (foo_bar + regexp) === '/foo-bar' #=> true
p (foo + regexp) === '/foo-bar' #=> true (but expected to return false)
##############################################
# my patch
regexp = Mustermann.new(%r{(?:/.*)?})
p (foo_bar + regexp) === '/foo-bar' #=> true
p (foo + regexp) === '/foo-bar' #=> false Under the above principle, even filter which does not expect to operate originally has been executed on the current pattern. |
So my patch makes it avoid the unexpected matching with filter. I guess this is reasonable. Thoughts? |
Because this patch affects namespace, which was changed in 2.0 to support Mustermann, we are fine to merge it. Thank you @namusyaka for your patch and explanation! |
Thank you for the patch and the explanation, @namusyaka, and thank you both for your patience! 🙇 |
Fixes #1251
@mwpastore @zzak Could you confirm this?