Skip to content

Avoid silently overwriting with merge #353

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

Merged
merged 1 commit into from
Feb 23, 2017

Conversation

composerinteralia
Copy link
Member

@composerinteralia composerinteralia commented Sep 15, 2016

At the moment merge! with an array will overwrite any existing hash
attributes. It should probably raise a MergeError. It also makes sense
to raise this error when attempting to merge a hash into an array, or
when trying to merge a non-hash-or-array.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rwz (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@composerinteralia
Copy link
Member Author

@rwz would you like me to rebase on master to keep this up to date?

lib/jbuilder.rb Outdated
def _try_merge(current_value, updates)
if ::Array === updates
if ::Array === current_value
return current_value + updates
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep the if/else structure and avoid the return keywords?

@composerinteralia composerinteralia force-pushed the raise-merge-errors branch 3 times, most recently from 9fc0347 to 7e723cf Compare February 23, 2017 04:08
At the moment merge! with an array will overwrite any existing hash
attributes. It should probably raise a MergeError. It also makes sense
to raise this error when attempting to merge a hash into an array, or
when trying to merge a non-hash-or-array.
@composerinteralia
Copy link
Member Author

composerinteralia commented Feb 23, 2017

@rafaelfranca thanks for your comment! I simplified what a had a bit. This version is closer to the original.

@rafaelfranca rafaelfranca merged commit 8911c05 into rails:master Feb 23, 2017
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.

4 participants