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

Fix coercing of string to 0 in parse_id #173

Merged
merged 1 commit into from
Nov 2, 2017
Merged

Fix coercing of string to 0 in parse_id #173

merged 1 commit into from
Nov 2, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Nov 2, 2017

Currently, parse_id returns a 0 if a string is passed in, rather than a hash. This checks to ensure the resource passed in is a hash and returns nil otherwise, allowing normal error handling to proceed.

I couldn't find a better place for the test, seems like it doesn't quite belong there and is more of a general case. Thoughts?

@miq-bot add_label bug, gaprindashvili/yes

Currently, parse_id returns a 0 if a string is passed in, rather than a hash. This extends the check on the resource to ensure it is a hash and allows normal error handling to proceed.
@miq-bot
Copy link
Member

miq-bot commented Nov 2, 2017

Checked commit jntullo@7bd90ca with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 3 offenses detected

spec/requests/services_spec.rb

Copy link
Member

@chrisarcand chrisarcand left a comment

Choose a reason for hiding this comment

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

I couldn't find a better place for the test, seems like it doesn't quite belong there and is more of a general case. Thoughts?

I think adding tests for specific bugs that happen to test general cases is fine; it's covered somewhere :)

LGTM

@@ -39,7 +39,7 @@ def validate_api_action
end

def parse_id(resource, collection)
return nil if resource.blank?
return nil if !resource.kind_of?(Hash) || resource.blank?
Copy link
Member

Choose a reason for hiding this comment

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

You don't need resource.blank? anymore, though it's fine that it short circuits the case below.

@chrisarcand chrisarcand merged commit 42813a2 into ManageIQ:master Nov 2, 2017
@chrisarcand chrisarcand added this to the Sprint 73 Ending Nov 13, 2017 milestone Nov 2, 2017
@abellotti
Copy link
Member

Thanks @jntullo for fixing this 👍

simaishi pushed a commit that referenced this pull request Nov 6, 2017
Fix coercing of string to 0 in parse_id
(cherry picked from commit 42813a2)
@simaishi
Copy link
Contributor

simaishi commented Nov 6, 2017

Gaprindashvili backport details:

$ git log -1
commit fbe9f2164f84634695ae26aa4d8d1aebcd63a3e7
Author: Chris Arcand <chrisarcand@users.noreply.github.com>
Date:   Thu Nov 2 10:45:11 2017 -0500

    Merge pull request #173 from jntullo/bug/fix_coerced_zero
    
    Fix coercing of string to 0 in parse_id
    (cherry picked from commit 42813a23b65b485609033cbaa8d65041549b2e6b)

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.

5 participants