Skip to content
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

Sinatra::Namespace breaks route with named parameters ? #1409

Closed
scalp42 opened this issue Mar 8, 2018 · 7 comments
Closed

Sinatra::Namespace breaks route with named parameters ? #1409

scalp42 opened this issue Mar 8, 2018 · 7 comments
Assignees
Milestone

Comments

@scalp42
Copy link

scalp42 commented Mar 8, 2018

Hi folks,

Running into an issue upgrading to Sinatra 2.

This route works fine without Sinatra::Namespace:

class TestController < MainController
  get '/i/love/:framework.?:format?' do
    params.to_json
  end
end
$> http --body localhost:9393/v1/i/love/sinatra

{
    "captures": [],
    "format": null,
    "framework": "sinatra"
}

$> http --body localhost:9393/v1/i/love/sinatra.json

{
    "captures": [],
    "format": "json",
    "framework": "sinatra"
}

If I try to namespace the same route with Sinatra::Namespace:

class TestController < MainController
  register Sinatra::Namespace

  namespace '/hey' do
    get '/i/love/:framework.?:format?' do
      params.to_json
    end
  end
end

It won't start:

$> bundle exec puma --port=9393 config.ru

Puma starting in single mode...
* Version 3.11.3 (ruby 2.5.0-p0), codename: Love Song
* Min threads: 2, max threads: 10
* Environment: development

! Unable to load application: Mustermann::Error: #<Class:0x00007fb6e10c22a0>: Cannot translate Mustermann::AST::Node::WithLookAhead

Here is the full trace: https://gist.github.com/scalp42/e627e470c6169e3f4be380cea327b697

Any ideas? 🤔

Thanks in advance for the help!

@namusyaka namusyaka self-assigned this Mar 9, 2018
@namusyaka
Copy link
Member

It's almost certainly a bug. I'll investigate this problem soon.
Thank you for the report.

@namusyaka namusyaka added this to the v2.0.2 milestone Mar 9, 2018
@scalp42
Copy link
Author

scalp42 commented Mar 9, 2018

No worries, thanks for looking into it! 🥇

@namusyaka
Copy link
Member

This is not sinatra issue, but mustermann issue.
The cause of this issue is to not process WithLookAhead node in Mustermann::Sinatra::SafeRenderer.
I sent a PR for fixing the issue.

@scalp42 Could you confirm it? Maybe the following code can be used.

gem 'mustermann', github: 'sinatra/mustermann', branch: 'fix-sinatra-concat'

@scalp42
Copy link
Author

scalp42 commented Mar 12, 2018

@namusyaka confirmed it's working!

Thanks a lot for looking into it ✌️

@namusyaka
Copy link
Member

@scalp42 Thanks! This bug could be fixed at the next mustermann release. sinatra/mustermann#87

@scalp42
Copy link
Author

scalp42 commented Jun 27, 2018

@namusyaka @rkh any idea when a new mustermann version will be released with the fix?

I'm assuming it should be safe to cut a new release?

Thanks in advance!

@namusyaka
Copy link
Member

@scalp42 Sorry for the late reply, I have just released mustermann v1.0.3. Please check it out.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Sep 23, 2018
Mustermann 1.0.3 (2018-08-17)

* Handle with_look_ahead on SafeRenderer. Fixes sinatra/sinatra#1409
  @namusyaka
* Fix EqualityMap#fetch to be compatible with the fallback Hash#fetch. Fixes
  #89 @eregon
* Improve code base and documentation. @sonots, @iguchi1124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants