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

Fixed edge case regarding Hash with inner param #1156

Merged
merged 1 commit into from
Sep 17, 2015

Conversation

lasseebert
Copy link
Contributor

This fixes an edge case where the API would blow up with a "no implicit conversion of Symbol into Integer".

To trigger the error, make a param nested inside a Hash param and add values validations to the param. Then send something that is not a hash to the outer param. (see spec)

@@ -7,6 +7,7 @@ def initialize(attrs, options, required, scope)
end

def validate_param!(attr_name, params)
return unless params.is_a?(Hash)
Copy link
Member

Choose a reason for hiding this comment

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

We are skipping the error here, shouldn't it be a fail?

Copy link
Member

Choose a reason for hiding this comment

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

Actually I take it back. The parent is the problem, we don't get deep enough to care about the values validator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just skips the validation of the inner param if the outer param does not have a valid value.

The "real" error happens in the coerce validator that correctly invalidates a Hash param with string value.

This is the same thing happening in the allow_blank validator here: https://github.com/ruby-grape/grape/blob/master/lib/grape/validations/validators/allow_blank.rb#L5

Copy link
Member

Choose a reason for hiding this comment

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

Yes I should first have coffee and then review code :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:) Always coffee first.

dblock added a commit that referenced this pull request Sep 17, 2015
Fixed edge case regarding Hash with inner param
@dblock dblock merged commit 790f2de into ruby-grape:master Sep 17, 2015
@dblock
Copy link
Member

dblock commented Sep 17, 2015

Merged, thanks.

@lasseebert
Copy link
Contributor Author

Thanks :)

@lasseebert lasseebert deleted the fix_hash_with_validated_param branch September 17, 2015 11:41
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

Successfully merging this pull request may close these issues.

2 participants