-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Avoid unexpected transformations for parameters
Restify checked every param if it responds to to_param, and calls it, before passing values to Addressable::Template. Since Rails patches to_param into anything, that resulted in accepting virtually anything somehow into params. For example, any Array was encoded a slash-delimited string of the individual values ([1,2] -> "1/2"), which not only could result in confusing things accidentially passed as params, but also made it impossible to pass a parameter multiple times (a: [1, 2] -> "a=1&a=2"). This commit takes the basic type detection from Addressable::Template and tries to only apply to_param, which addressable does not support at all, for non-basic types. Therefore, arrays and hash, should behave similar to when passed directly to Addressable::Template, but it will still be possible to e.g. pass an ActiveRecord model as a parameter, using #to_param. This makes passing standard and Rails-style argument lists possible: expand(p: [1, 2]) -> "/?p=1&p=2" expand('p[]': [1, 2]) -> "/?p%5B%5D=1&p%5B%5D=2" Fixes #44
- Loading branch information
Showing
2 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters