Skip to content

ro/cf: strip RO country prefix in compact() for consistent output - #499

Open
gaoflow wants to merge 2 commits into
arthurdejong:masterfrom
gaoflow:fix-ro-cf-compact
Open

ro/cf: strip RO country prefix in compact() for consistent output#499
gaoflow wants to merge 2 commits into
arthurdejong:masterfrom
gaoflow:fix-ro-cf-compact

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #485. stdnum.ro.cf produced inconsistent output depending on whether the optional RO country prefix was present in the input:

>>> validate('RO 185 472 90')
'RO18547290'          # before
>>> validate('185 472 90')
'18547290'

Both inputs denote the same number, but compact() did not strip the RO prefix the way the cui.compact() it delegates to (and other country modules such as pl/nip) do.

Fix

  • compact() now strips the RO prefix, returning the domestic form — matching cui.compact() and sibling modules.
  • validate() is simplified: the manual RO split is removed since compact() now handles it.
  • The docstring example is updated to reflect '18547290'.

validate('RO 185 472 90') and validate('185 472 90') now both return '18547290'.

This pull request was prepared with the assistance of AI, under my direction and review.

validate('RO 185 472 90') previously returned 'RO18547290' while
validate('185 472 90') returned '18547290' for the same number,
making the output format depend on the input form. compact() now
strips the optional RO VAT prefix so validate() always returns the
domestic CUI/CIF digits, consistent with cui.compact() and the
behaviour of other country modules such as pl/nip.

Closes arthurdejong#485.
@arthurdejong

Copy link
Copy Markdown
Owner

Hi @gaoflow,

This change fails the tests. In particular this number is accepted as valid while it is not: RO RO 16621241

Also see the discussion in #485 that describes some of the history and complexity of the current implementation.

@gaoflow

gaoflow commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching that. Fixed in GPG-verified 87f99de.

The issue was that after cf.compact() stripped one optional RO, the remaining RO16621241 still went through cui.validate(), whose own compacting accepts RO again. I added an explicit domestic-form digit check in cf.validate() after its single prefix strip, so RO 185 472 90 still returns 18547290, while RO RO 16621241 now raises InvalidFormat.

Verification:

PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest -o addopts='' --doctest-modules --doctest-glob='*.doctest' tests/test_eu_vat.doctest stdnum/ro/cf.py -q
2 passed
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python3 -m pytest -o addopts='' --doctest-modules stdnum/ro -q
4 passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behavior with country prefixes

2 participants