Copy object item key to replacement in ReplaceItemViaPointer #859
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
README indicates that object items can be replaced with
cJSON_ReplaceItemViaPointer
. However, the key for an object item will be lost in that process, unless the caller uses information on cJSON internals to update the replacement object's key with that of the source.cJSON_ReplaceItemInObject
is listed as the other method for replacing an object item, and does set the key on the replacement value.This PR updates
cJSON_ReplaceItemViaPointer
to copy any string on the item to be replaced with that of the source.Consideration was made to just reuse the string from the item being replaced - opted to effectively replicate the existing functionality of
cJSON_ReplaceItemInObject
, which always allocated a new string for key.Example:
Under
master
, this prints:After this PR:
Couldn't find contributor guidelines at a glance, so let me know if there are any other specifics needed here.