Skip to content

Nested namespace with optional url parts do not work in sinatra => 2.0 #1361

@lvonk

Description

@lvonk

Hi,

I have the following app (which worked in sinatra < 2.0):

class App < Sinatra::Base
  register Sinatra::Namespace

  namespace '/foo/:year/?:period?' do
    get '/status' do
      status 200
    end

    namespace '/nested' do
      get '/1' do
        this_method_does_not_exist('hello')
        status 200
      end

      helpers do
        def this_method_does_not_exist(msg)
          puts "hello #{msg}"
        end
      end
    end
  end
end

When I call /foo/2018/2/nested/1 all works as expected. When I call /foo/2018/nested/1 it results in a

NoMethodError: undefined method `this_method_does_not_exist`

Duplicating the outer namespace "resolves" the issue:

class App < Sinatra::Base
  register Sinatra::Namespace

  namespace '/foo/:year/?:period?' do
    get '/status' do
      status 200
    end
  end
  
  namespace '/foo/:year/?:period?/nested' do
    get '/1' do
      this_method_does_not_exist('hello')
      status 200
    end

    helpers do
      def this_method_does_not_exist(msg)
        puts "hello #{msg}"
      end
    end
  end

end

Full test case can be found here: https://github.com/lvonk/sinatra-namespaces-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions