Closed Alex-Usmanov closed 11 months ago
Hi! Sorry for late response.
Turns out the issue was slightly different that I anticipated (moreover, some tests were failing in my version of solution). So, the issue is: when formatting a national number, a transformRule might be applied when it is unnecessary.
For instance we shall take this number: 4416666
When parsing it with destinationCountry=IsoCode.BM
, the transform rule is applied and 4416666 turns into 4414416666.
(notice how 441 was applied twice via transformRule
)
To fix this, I added a check to the transform function to see if the number is already transformed and do not make the transformation again.
Added a test case:
phone_number_test.dart:190
Sorry for the late reply from myself too.
At first glance I've the following worries:
nationalPrefixFormattingRule
of the sort r"$NP$FG"
which I'm not sure how that'd interact with the given code.Would this alternative solution of only apply ing the transform rule when the phone number is valid work ?
I'm taking a look once again at this to fix it, but I do not understand the actual issue. Could you create an issue with the steps to reproduce your issue ? Please go in detail so there is no misunderstanding. I'm going to close this until then and will reopen if the issue is created.
When removing a national prefix in national number parser, sometimes the removal does not occur (and further down the line, when transform rule is applied, weird behavior is encountered).
In order to remedy this (and allow for type-as-you-go formatting), a measure is necessary to remove the previously applied transform rule (leadingDigits from metadata do not reflect transform rule all the time - example isocode=cc). So, I added a mechanism for removal of this transform rule (which is usually the national prefix).