From 8db7da44f29848acefe55767b00d192db8741390 Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Wed, 24 Jun 2026 16:29:59 +0200 Subject: [PATCH 1/2] ro/cf: strip RO country prefix in compact() for consistent output 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 #485. --- stdnum/ro/cf.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/stdnum/ro/cf.py b/stdnum/ro/cf.py index 918df30a..f0511106 100644 --- a/stdnum/ro/cf.py +++ b/stdnum/ro/cf.py @@ -20,8 +20,8 @@ The Romanian CF is used for VAT purposes and can be from 2 to 10 digits long. ->>> validate('RO 185 472 90') # VAT CUI/CIF -'RO18547290' +>>> validate('RO 185 472 90') # VAT CUI/CIF (RO prefix is stripped) +'18547290' >>> validate('185 472 90') # non-VAT CUI/CIF '18547290' >>> validate('1630615123457') # CNP @@ -37,8 +37,12 @@ def compact(number: str) -> str: """Convert the number to the minimal representation. This strips the - number of any valid separators and removes surrounding whitespace.""" - return clean(number, ' -').upper().strip() + number of any valid separators and removes surrounding whitespace. The + optional RO country prefix is removed to return the domestic form.""" + number = clean(number, ' -').upper().strip() + if number.startswith('RO'): + number = number[2:] + return number # for backwards compatibility @@ -49,13 +53,10 @@ def validate(number: str) -> str: """Check if the number is a valid VAT number. This checks the length, formatting and check digit.""" number = compact(number) - cnumber = number - if cnumber.startswith('RO'): - cnumber = cnumber[2:] - if len(cnumber) == 13: + if len(number) == 13: # apparently a CNP can also be used (however, not all sources agree) - cnp.validate(cnumber) - elif 2 <= len(cnumber) <= 10: + cnp.validate(number) + elif 2 <= len(number) <= 10: cui.validate(number) else: raise InvalidLength() From 87f99de971bee213075ec5962993419141c88330 Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Thu, 20 Aug 2026 13:26:30 +0200 Subject: [PATCH 2/2] ro/cf: reject duplicated RO prefix after compact --- stdnum/ro/cf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdnum/ro/cf.py b/stdnum/ro/cf.py index f0511106..80b72338 100644 --- a/stdnum/ro/cf.py +++ b/stdnum/ro/cf.py @@ -22,6 +22,10 @@ >>> validate('RO 185 472 90') # VAT CUI/CIF (RO prefix is stripped) '18547290' +>>> validate('RO RO 16621241') +Traceback (most recent call last): + ... +InvalidFormat: ... >>> validate('185 472 90') # non-VAT CUI/CIF '18547290' >>> validate('1630615123457') # CNP @@ -32,7 +36,7 @@ from stdnum.exceptions import * from stdnum.ro import cnp, cui -from stdnum.util import clean +from stdnum.util import clean, isdigits def compact(number: str) -> str: @@ -53,6 +57,8 @@ def validate(number: str) -> str: """Check if the number is a valid VAT number. This checks the length, formatting and check digit.""" number = compact(number) + if not isdigits(number): + raise InvalidFormat() if len(number) == 13: # apparently a CNP can also be used (however, not all sources agree) cnp.validate(number)