Fix: prevent adding keys with undefined values to the yar object in lazy mode #160
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.
This PR adds a check before copying stored keys to the
yarobject in lazy mode to prevent adding undefined values.Problem
In some cases the
yar.onPreAuth()can be called several times in a row without anyyar.onPreResponse()call in between.In
lazymode, this causes the properties moved from the internal_storeto theyarobject to be overridden with undefined values.Example with a "authorize" lazy key:
onPreAuth: "authorize" property is moved from the_storeto theyarobject in the_initialize().onPreAuth: the "authorize" key is still the_store._lazyKeysso the code tries to move the "authorize" value from the store to theyarobject. However this was already moved in (1), so this results in the "authorize" property on theyarobject to be overridden with an "undefined" value.Solution
Only move the properties if they exist in the
_store.Alternative solution
Empty the
_lazyKeysafter moving the values in_initialize(). Note: deleting the_lazyKeyswould result in thelazymode to be reseted to false, so_lazyKeysneeds to be set to[]instead of being deleted.