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

convert non-string default params to strings in the router. #9439

Merged
merged 1 commit into from Feb 26, 2013

Conversation

senny
Copy link
Member

@senny senny commented Feb 26, 2013

Closes #9435.

Since Rails 4.0.0.beta1 Rails raises an exception when non-string default params
are provided in the router (eg. root to: 'main#posts', page: 1).

I see sevaral options to fix this:

  1. issue a deprecation warning when non-string defaults are used.
  2. convert all default params to strings.
  3. get the router to work with non-string params (implemented by this patch).

I chose 3. becuase it's the only option, which is backwards compatible.
With 3.2.x the router happily accepted non-string default params.

@senny
Copy link
Member Author

senny commented Feb 26, 2013

@rafaelfranca I'll need to move the Changelog entry into the unreleased section.

@senny
Copy link
Member Author

senny commented Feb 26, 2013

@pixeltrix could you take a look?

@pixeltrix
Copy link
Contributor

@senny my only concern is why is this error occurring - the params value should only contain path parameters which should be strings (It should be accessing the environment key action_dispatch.request.path_parameters). Have you reproduced this in a simple Rails 4 app and does your test fail without the change?

@senny
Copy link
Member Author

senny commented Feb 26, 2013

@pixeltrix yes the test does fail indeed with the same exception as described in the referenced issue. As the title of the PR suggest my first implementation used to convert all params to strings but there were other unpleasant side-effects. I agree that the default's should always be strings the thing is, in 3.2.x it worked the way it does after this patch.

@senny
Copy link
Member Author

senny commented Feb 26, 2013

@pixeltrix how would you like to proceed on this one?

@pixeltrix
Copy link
Contributor

@senny I'm investing this at the moment to see why there are non-string params in path parameters

@senny
Copy link
Member Author

senny commented Feb 26, 2013

They are coming directly from the route definition and are added in this method: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#L150-L171

I don't think a normal request ever produces other values than strings but the defaults you can supply in the routes file can have different types and 3.2.x passed them through as is.

@@ -1,5 +1,14 @@
## Rails 4.0.0 (unreleased) ##

* Allow non-string default params in the router.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to:

*   Skip valid encoding checks for non-String parameters that come from the matched route's defaults.

@pixeltrix
Copy link
Contributor

Surprised this hasn't come up before we released beta1 - the responsible commit is quite old: 3fc561a

@senny
Copy link
Member Author

senny commented Feb 26, 2013

@pixeltrix sometimes I am really surprised how long a particular bug will reside in rails without being noticed. I updated the CHANGELOG and pushed a rebased version.

@pixeltrix
Copy link
Contributor

@senny can you edit the commit message so it's less about what we could do and just explain what the commit does - thanks.

Closes rails#9435.

Skip valid encoding checks for non-String parameters that come
from the matched route's defaults.
@senny
Copy link
Member Author

senny commented Feb 26, 2013

used the commit message you suggested.

pixeltrix added a commit that referenced this pull request Feb 26, 2013
convert non-string default params to strings in the router.
@pixeltrix pixeltrix merged commit 6a235fa into rails:master Feb 26, 2013
@pixeltrix
Copy link
Contributor

Sorry, my bad - it looks like GitHub uses the original commit message on the Commits tab for a PR even after you force push an update.

@senny senny deleted the 9435_router_params_as_integers branch February 26, 2013 21:03
@senny
Copy link
Member Author

senny commented Feb 26, 2013

@pixeltrix ah no you were totally right ;) I replaced the message and made the comment afterwards. Thanks for the good review.

@pixeltrix
Copy link
Contributor

@senny I see what happened - the GH dynamic updating of comments on the PR showed me your new comment but didn't update the commits tab.

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

Successfully merging this pull request may close these issues.

Rails 4: NoMethodError - undefined method `valid_encoding?' for 1:Fixnum:
2 participants