Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Parsing US number succeeds in tests fails in actual usage #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

ajayrungta
Copy link

US number parsing fails because different data is used for countryCallingCodeToRegionCodeMap while testing and actual usage. The mapping for global networks (880 => 001) is present in countryCallingCodeToRegionCodeMapForTesting but not in countryCallingCodeToRegionCodeMap.

When the init() is called inside PhoneNumberUtil::getInstance(), it removes US from the supportedRegions array.

At line, http://git.io/CLseew#L235
unset($this->supportedRegions[array_search(self::REGION_CODE_FOR_NON_GEO_ENTITY, $this->supportedRegions)]) resolves to
unset($this->supportedRegions[array_search(001, $this->supportedRegions)])

Because the mapping doesn't exist for 001, array_search returns FALSE executing unset($this->supportedRegions[FALSE].

As unset(array[FALSE]) is equivalent to unset(array[0]), it unset the entry for US from the supportedRegions as index for US is 0 in the array.

Hence, parsing US number results into error.

I have attached a possible solution. Please validate and pull.

ajayrungta and others added 16 commits May 15, 2012 16:06
* Updates namespace from com\google\i18n\phonenumbers to libphonenumber
* Updates comments & README for namespace change
* Moves multiple classes in single file to individual classes
* Adds use & require_once statements in tests, build & demo.php accordingly
Mobile pattern update to match 8551###### as valid indian mobile number
Mobile pattern update to match 8747###### as valid indian mobile number
Mobile pattern update to match 8740###### as valid indian mobile number
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants