fix(bolt11): replace confusing in operator with explicit range check for recovery flag#149
Merged
Conversation
…for recovery flag The decode function used recoveryFlag in [0, 1, 2, 3] to validate the recovery flag. The in operator checks property names (array indices), not values. While it happened to work because the array indices are 0,1,2,3, it is misleading and not the right tool for this check. Changes: - Replace !(recoveryFlag in [0, 1, 2, 3]) with recoveryFlag < 0 || recoveryFlag > 3 - The range check is clearer, more explicit, and does not rely on the coincidence that array indices match the valid recovery flag values Verification: - All 52 tests pass - npm run build completes successfully - No behavior change — the same values are rejected and accepted
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
The
decodefunction usedrecoveryFlag in [0, 1, 2, 3]to validate the recovery flag. Theinoperator checks property names (array indices), not values.Problem
inchecks if a value is a property of the object, not if it is a value in the array0, 1, 2, 3, but this is coincidental and misleadingChanges
!(recoveryFlag in [0, 1, 2, 3])withrecoveryFlag < 0 || recoveryFlag > 3Verification
npm run buildcompletes successfully