Repository navigation
Conversation
…Many() has() and hasMany() used Boolean() on the value. take() used a falsy check. Thus a stored 0, false, "", or null showed as missing, and take() did not remove the entry. Now each method compares the value with undefined.
This branch has not been deployed
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.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix. Fixes #1766.
Problem
CacheableMemorytreats a stored falsy value as a missing key in four methods:The result is the same for
false,"", andnull.has()andhasMany()useBoolean(item)on the value.take()usesif (!item), so it also does not delete the entry.takeMany()callstake().The
KeyvCacheableMemoryadapter has the same problem inget(). It usesif (result), so it returnsundefinedfor a stored falsy value. After thehas()fix, the adapterhas()returnstruefor the same key.Fix
has()andhasMany()returnthis.get(key) !== undefined.take()returns early only when the value isundefined.KeyvCacheableMemory.get()returns the result of the storeget()directly.The methods still read through
get(). Thus stats, hooks, LRU order, and expiry stay the same.Verification
main: 2 failed, 138 passed (140).get()fix:expected undefined to be +0.pnpm test:ciinpackages/memorypasses 163 of 163 tests.packages/memorystays at 100% for statements, branches, functions, and lines.Test audit
CacheableMemory Has > should return true for falsy valueshas()andhasMany()returntruefor a key that holds0,false,"", ornull.main. The test fails onmain.hastests use only truthy values.CacheableMemory Take > should take and delete falsy valuestakeMany()(and through ittake()) returns falsy values and removes their entries.take(), as onmain. The test fails onmain.taketests use only truthy values.Keyv Cacheable Memory > should keep falsy values in has(), get(), and getMany()has(),get(), andgetMany()agree for0,false,"", andnull.get(). The test fails on the code before the fix.No existing test was changed or deleted.