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

Change filter on /rails/info/routes to use an actual path regexp from rails #18434

Merged
merged 1 commit into from
Feb 26, 2015

Conversation

brainopia
Copy link
Contributor

Change filter on /rails/info/routes to use an actual path regexp from rails
and not approximate javascript version. Oniguruma supports much more
extensive list of features than javascript regexp engine.

Fixes #18402 (by removing json_regexp which breaks down on complex regexp patterns)

cc @schneems @rafaelfranca

@brainopia brainopia force-pushed the change_filter_on_rails_info_routes branch from 69dbae8 to 7b7acae Compare January 10, 2015 13:27
@brainopia
Copy link
Contributor Author

Example of filtering on a complex pattern (which breaks /rails/info/routes page and rake routes on master)

@arthurnn
Copy link
Member

@schneems what do you think?

@rohitarondekar
Copy link
Contributor

I've only given a cursory look at the PR but in general I agree with the direction. The conversion of Ruby compatible regexp to JS compatible is fragile and will be prone to errors. Also rake routes is an important command that ought not to break just because there is a complex regexp.

Another alternative will be to catch the error during conversion and revert back to original regexp. Basically if you get till the conversion the original regexp is fine but converting it is not working out so print the regex as-is. Of course this leads to inconsistency and might be surprising.

@schneems
Copy link
Member

Thanks for the work, and sorry for the delay. This is a pretty big change for a pretty small bug. As you noted, this page doesn't have any tests, so i've hesitant to merge in large changes. Moving the processing to the server side is a bit heavy handed. I'm 👎 on it as is. Can we modify the regex sanitizer to remove comments?

@brainopia
Copy link
Contributor Author

The ruby regexp engine supports much more features than javascript version.
Why try to achieve a working approximation when exact match can be achieved?

If you worry about complex logic, then you shouldn't. I've removed more lines of code than I've added and the logic is straightforward.

@rafaelfranca
Copy link
Member

Also we want to make it possible to use the fuzzy match in the rake tasks
so it is better to have to logic at Ruby side.

On Wed, Feb 18, 2015, 21:33 Ravil Bayramgalin notifications@github.com
wrote:

The ruby regexp engine supports much more features than javascript version.
Why try to achieve a working approximation when exact match can be
achieved?

If you worry about complex logic, then you shouldn't. I've removed more
lines of code than I've added (including a big changelog entry) and the
logic is straightforward.


Reply to this email directly or view it on GitHub
#18434 (comment).

@schneems
Copy link
Member

I'm convinced. I'll test out the implementation locally in the next day or so.

Is there anyway to test any of this? Are we doing integration style tests on any of the other internal controllers?

@rafaelfranca
Copy link
Member

Maybe unit test in the fuzzy match class? But I think we have tests to the
info controller

On Wed, Feb 18, 2015, 21:42 Richard Schneeman notifications@github.com
wrote:

I'm convinced. I'll test out the implementation locally in the next day or
so.

Is there anyway to test any of this? Are we doing integration style tests
on any of the other internal controllers?


Reply to this email directly or view it on GitHub
#18434 (comment).

@schneems
Copy link
Member

I verified and it works as promised. We should add a test to https://github.com/rails/rails/blob/master/railties/test/rails_info_controller_test.rb to test the results of querying for a partial and full match return as expected.

This commit did break the routing error page: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb

Basically whenever you get a routing exception you get a very similar view to rails/info/routes that lets you debug the problem on the same page. It needs to be updated to use the new server architecture

@brainopia brainopia force-pushed the change_filter_on_rails_info_routes branch 2 times, most recently from 7fecb5c to f970850 Compare February 23, 2015 16:52
@brainopia
Copy link
Contributor Author

@schneems Thank you for feedback!

I've fixed the issue with routing_error.html.erb page (I was using a relative path in javascript, changed it to absolute to work from arbitrary locations).

And I've added tests.

… rails

Change filter on /rails/info/routes to use an actual path regexp from rails
and not approximate javascript version. Oniguruma supports much more
extensive list of features than javascript regexp engine.

Fixes rails#18402.
@brainopia brainopia force-pushed the change_filter_on_rails_info_routes branch from f970850 to 321db4a Compare February 23, 2015 16:57
@schneems
Copy link
Member

The error page works, your page works. I agree this is cleaner and simpler than my first version. Thanks for the PR, merging in ❤️ ❤️ ❤️

schneems added a commit that referenced this pull request Feb 26, 2015
…routes

Change filter on /rails/info/routes to use an actual path regexp from rails
@schneems schneems merged commit f069b41 into rails:master Feb 26, 2015
@brainopia
Copy link
Contributor Author

Thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rake routes fails when route constraint regex contains comments
5 participants