Skip to content

fix: accept numbers written with their usual separators (se, cl, uy) - #165

Merged
koblas merged 1 commit into
koblas:mainfrom
gaoflow:fix-clean-normalisation-se-cl-uy
Aug 1, 2026
Merged

fix: accept numbers written with their usual separators (se, cl, uy)#165
koblas merged 1 commit into
koblas:mainfrom
gaoflow:fix-clean-normalisation-se-cl-uy

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

clean() in four modules doesn't normalise the input to the shape validate()'s length check expects, so each rejects the identifier as it is normally written.

se/personnummer requires the separator, so the bare 10- and 12-digit forms are InvalidLength — though format() has always accepted them:

validate('880320-0016')  -> OK            // already in the tests
validate('8803200016')   -> InvalidLength
validate('198803200016') -> InvalidLength
format('8803200016')     -> '880320-0016'

Per Folkbokföringslagen (1991:481) §18 the number contains "födelsetid, födelsenummer och kontrollsiffra" — the hyphen is written between them (and becomes + the year someone turns 100), so it isn't part of the number. python-stdnum's se.personnummer.compact() inserts the default - at those two lengths; that step wasn't ported. Finishes #97 on the validate() side.

cl/rut, uy/cedula, uy/nie don't strip the . their own format() emits, so validate(format('125319092')), validate(format('12345672')) and validate(format('912345670')) are all InvalidLength.

These are the only four: I checked all 198 modules by re-running every valid example in the specs through python-stdnum in 8 written forms, by validate(format(x))/validate(compact(x)), and by feeding python-stdnum's canonical format() back in. All three probes are empty afterwards. Where the port is deliberately ahead of python-stdnum I left it — tw/ubn (#159) and samordningsnummer, which upstream still rejects.

Tests reuse existing fixtures with only the separator changed, plus a bad check digit in each new form. npm test 1627 pass (+17); the mx/curp failure is pre-existing on main.

clean() in these four modules does not normalise the input to the shape
validate()'s length check expects.

se/personnummer required the -/+ separator, so the bare 10 and 12 digit
forms were InvalidLength even though format() accepted them. The separator
is written between the birth date and the birth number, it is not part of
the number (Folkbokforingslagen 1991:481 §18); python-stdnum inserts the
default '-' for those two lengths in compact() and that step was not
ported.

cl/rut, uy/cedula and uy/nie did not strip the '.' that their own format()
emits, so each rejected its own standard presentation.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@koblas
koblas merged commit 6556bd9 into koblas:main Aug 1, 2026
2 checks passed
@gaoflow

gaoflow commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The branch is ready to merge.

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.

2 participants