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
yar
object 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
lazy
mode, this causes the properties moved from the internal_store
to theyar
object to be overridden with undefined values.Example with a "authorize" lazy key:
onPreAuth
: "authorize" property is moved from the_store
to theyar
object in the_initialize()
.onPreAuth
: the "authorize" key is still the_store._lazyKeys
so the code tries to move the "authorize" value from the store to theyar
object. However this was already moved in (1), so this results in the "authorize" property on theyar
object to be overridden with an "undefined" value.Solution
Only move the properties if they exist in the
_store
.Alternative solution
Empty the
_lazyKeys
after moving the values in_initialize()
. Note: deleting the_lazyKeys
would result in thelazy
mode to be reseted to false, so_lazyKeys
needs to be set to[]
instead of being deleted.