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

Bug: Serializing boolean false value returns nil #130

Closed
samsongz opened this issue Jan 19, 2019 · 2 comments
Closed

Bug: Serializing boolean false value returns nil #130

samsongz opened this issue Jan 19, 2019 · 2 comments

Comments

@samsongz
Copy link

samsongz commented Jan 19, 2019

hey team! we found a bug in the serialization of boolean false values as follows:

To recreate:

TestClass = Class.new(Blueprinter::Base) do
  identifier :id
  field :active
end

data = {
  id: 1,
  active: false
}

TestClass.render(data)

The output of .render is: "{\"id\":1,\"active\":null}"

It is coming from the extract method of HashExtractor
https://github.com/procore/blueprinter/blob/f2415a3fa0ec835ac12cf39d92974eae14ca879b/lib/blueprinter/extractors/hash_extractor.rb#L1-L7

Because the first condition evaluates to false (the correct value to be returned) it evaluates the second, which looks for a string key that doesn't exist, returning nil.

I have a branch with a spec to recreate and a suggested fix (remove the second OR condition) that I'd be happy to open a PR for to discuss or get feedback ✌️

@AllPurposeName
Copy link
Contributor

Great find. Shoot up that PR!

@mcclayton
Copy link
Contributor

Closing this as it has been fixed in #132

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

No branches or pull requests

3 participants