Fix: encodeDates mutates the object passed to people.set (#479) - #608
Open
sarmah-rup wants to merge 1 commit into
Open
Fix: encodeDates mutates the object passed to people.set (#479)#608sarmah-rup wants to merge 1 commit into
sarmah-rup wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What I hit
I passed a
Datetomixpanel.people.set(...)and theDateon my own object silently turned into a string on the next render, which broke a date-picker bound to that object. This is issue #479.Minimal repro:
Why
_.encodeDates(src/utils.js) writes the encoded strings back onto the object it is given (obj[k] = _.formatDate(v)) and recurses onto the same nested references, so it edits the exact object the caller passed topeople.set/set_once(and groupset).Fix
Build a copy instead of mutating the input. The encoded output is identical to before; only the side effect on the caller's object is removed. (
_.isObjectexcludes arrays, so recursion still only descends into plain objects.)Test
Added cases to
tests/unit/utils.js: encoding still works (top-level + nested) and the input object is no longer mutated (top-level + nested). Fulltests/unit/*suite passes (684 passing, 0 failing) andeslint ./srcis clean.Closes #479.