Skip to content

fix(bolt11): replace confusing in operator with explicit range check for recovery flag#149

Merged
andrerfneves merged 1 commit into
mainfrom
maintenance/fix-recovery-flag-check-20260605
Jun 12, 2026
Merged

fix(bolt11): replace confusing in operator with explicit range check for recovery flag#149
andrerfneves merged 1 commit into
mainfrom
maintenance/fix-recovery-flag-check-20260605

Conversation

@andrerfneves

Copy link
Copy Markdown
Owner

Summary

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.

Problem

  • in checks if a value is a property of the object, not if it is a value in the array
  • For arrays it happens to work because the indices are 0, 1, 2, 3, but this is coincidental and misleading
  • If the array values ever changed, the check would still behave the same (checking indices), which is a footgun

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

…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
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lightning-decoder Ready Ready Preview, Comment Jun 5, 2026 4:08am

@andrerfneves andrerfneves merged commit f59acfa into main Jun 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant