Skip to content

Breakage with trailing slash #1

@HoneyryderChuck

Description

@HoneyryderChuck

I get a backtrace crash with a very simple example: I set a rest resource endpoint, and when I GET the endpoint without the trailing slash, it works. When I don't, it throws an error and gets unhandled. Here's part of the backtrace that might be relevant:

#<ArgumentError: wrong number of arguments (given 1, expected 0)>                                                     
/home/.bundle/ruby/2.3.0/gems/roda-rest_api-2.0.1/lib/roda/plugins/rest_api.rb:233:in `block in index'
/home/.bundle/ruby/2.3.0/gems/roda-2.20.0/lib/roda.rb:807:in `if_match'
/home/.bundle/ruby/2.3.0/gems/roda-2.20.0/lib/roda.rb:743:in `_verb'
/home/.bundle/ruby/2.3.0/gems/roda-2.20.0/lib/roda.rb:370:in `get'
/home/.bundle/ruby/2.3.0/gems/roda-rest_api-2.0.1/lib/roda/plugins/rest_api.rb:234:in `index'
/home/.bundle/ruby/2.3.0/gems/roda-rest_api-2.0.1/lib/roda/plugins/rest_api.rb:89:in `block in routes!'

Here is a small route dec to reproduce the issue:

route do |r|
  r.on "foo" do
    "bar"
  end
  r.api path: '' do
    r.version 1 do
      r.resource :foos do |foos|
        foos.list { %w(bar) * 8  }
      end
    end
  end
end

Now use curl and fetch the following URLs:

  • http://%{host}:{port}/foo
  • http://%{host}:{port}/foo/
  • http://%{host}:{port}/v1/foos
  • http://%{host}:{port}/v1/foos/

With this example I demonstrate that the problem is not roda (I'm using 2.21), which correctly handles the trailing slash. You can also see that this gem uses the #get method to set the show/index, and roda doesn't handle trailing slashes with this. But even when that happens, roda doesn't crash (just 404's).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions