Skip to content

fix(nl/btw, se/personnummer): return invalid for empty input instead of throwing - #269

Merged
koblas merged 1 commit into
koblas:mainfrom
bardrop-oss:fix-empty-input-crash
Nov 20, 2026
Merged

koblas merged 1 commit into
koblas:mainfrom
bardrop-oss:fix-empty-input-crash

Conversation

@bardrop

@bardrop bardrop commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #268

stdnum.NL.btw.validate('') and stdnum.SE.personnummer.validate('') threw a TypeError instead of returning an invalid result. The same happened through validateVat('NL', ''), validateEntity('NL', '') and validatePerson('SE', '').

Both clean() functions destructured strings.splitAt(). splitAt drops empty parts, so for an empty value the first part was undefined. The fix uses plain slice calls there. For any value long enough to fill every part, the result is the same as before.

Tests: a validate:empty case in nl/btw.spec.ts and se/personnummer.spec.ts. Both fail on main with the TypeError and pass with the fix. npm test passes (4719 tests) and so does npm run lint. I also ran every validator on ~4000 random short strings each. Nothing else throws.

…of throwing

validate('') threw a TypeError in both validators. clean() destructured
strings.splitAt(), which drops empty parts, so the first part was
undefined for an empty (or very short) value. Use plain slices there.
@koblas
koblas merged commit b32eda8 into koblas:main Nov 20, 2026
7 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.

NL btw and SE personnummer validate() throw a TypeError on empty input

2 participants