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

Respond with 404 when snip part method has wrong arity #11

Conversation

Projects
None yet
2 participants
@floehopper
Copy link
Contributor

commented Jun 26, 2016

See freerange/site#34.

This isn't the most elegant solution. I did start by trying to obtain an instance of the part method and then calling Method#arity to check it is zero, but this isn't straightforward, because Snip instances respond to methods which aren't actually defined i.e. via Object#method_missing.

I also did a bit of investigation into why the #h & #html_escape methods exist at all, given that Soup::EmptyClass tries to remove all methods. I'm pretty sure it's because ERB::Util is included at the top-level in lib/vanilla/renderers/erb.erb. However, I tried a few ways to reduce the scope of this module inclusion, but couldn't get anything to work.

Respond with 404 when snip part method has wrong arity
See freerange/site#34.

This isn't the most elegant solution. I did start by trying to obtain an
instance of the part method and then calling `Method#arity` to check it is zero,
but this isn't straightforward, because `Snip` instances respond to methods
which aren't actually defined i.e. via `Object#method_missing`.

I also did a bit of investigation into why the `#h` & `#html_escape` methods
exist at all, given that `Soup::EmptyClass` tries to remove all methods. I'm
pretty sure it's because `ERB::Util` is included at the top-level in
`lib/vanilla/renderers/erb.erb` [1]. However, I tried a few ways to reduce the
scope of this module inclusion, but couldn't get anything to work.

[1]: https://github.com/lazyatom/vanilla-rb/blob/1f1c5624d75e5072706953ce28bee8deb5b099ad/lib/vanilla/renderers/erb.rb#L2
@floehopper

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2016

@lazyatom:

Do you have any thoughts on this PR? Are you likely to accept it?

As far as I can tell the CI build failure is unrelated to my change.

@lazyatom

This comment has been minimized.

Copy link
Owner

commented Jul 5, 2016

I'm taking a look at why Vanilla is including ERB::Util at the top level

@lazyatom

This comment has been minimized.

Copy link
Owner

commented Jul 5, 2016

I believe I've resolved this through a different mechanism; now, if snips don't explicitly respond to the requested part, you'll see the 404 response. The involved fixing a bug in soup as well as vanilla-rb, and you can see the results in the 2.0.0.beta version of the vanilla-rb gem that I just released. If you can confirm that this fixes the bug you saw, I think we can close this.

@floehopper

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2016

Sorry for not replying sooner. I haven't had a chance to try out your fix, but as long as the #h method is no longer added to a snip, it sounds as if it solve my problem. I suggest we close this and I'll get back to you if it doesn't solve my problem.

@floehopper floehopper closed this Jul 15, 2016

@floehopper

This comment has been minimized.

Copy link
Contributor Author

commented Jul 15, 2016

I can now confirm that this has fixed my issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.