Fix: prevent adding keys with undefined values to the yar object in lazy mode#160
Open
orakili wants to merge 1 commit intohapijs:masterfrom
Open
Fix: prevent adding keys with undefined values to the yar object in lazy mode#160orakili wants to merge 1 commit intohapijs:masterfrom
orakili wants to merge 1 commit intohapijs:masterfrom
Conversation
Member
|
It's possible I've missed something here, but I do not believe yar's If I've misunderstood here, would you be able to write a failing test case to illustrate? I believe that in order land a fix like this we will need to add a test to ensure this case is covered in the test suite. |
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.
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.