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

Fix: regex error with leading_digits #50

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

Conversation

jkronz
Copy link

@jkronz jkronz commented Apr 10, 2017

When parsing leading_digits for number formats, ^ is being
concatenated to the format, but many leading_digit formats contain the
| operator. For this reason, Format#match returns some false
positives. I.E., /^2|5[56]/ matches the phone number 1582380560.

This commit wraps the leading_digits expression in ()s before applying
the ^ so all of the formats must match the start of the line.

jkronz and others added 3 commits April 10, 2017 14:14
When parsing `leading_digits` for number formats, `^` is being
concatenated to the format, but many leading_digit formats contain the
`|` operator. For this reason, `Format#match` returns some false
positives. I.E., /^2|5[56]/ matches the phone number 1582380560.

This commit wraps the leading_digits expression in ()s before applying
the ^ so all of the formats must match the start of the line.
When we generate the national format for a given phone number,
the output format is specified by the global_phone.json database.
For example, New Zealand is '$1-$2 $3' where $1 is the national prefix,
$2 is the first group of digits, and $3 is the last group of digits.
However, when the national prefix is added to the number, we are
erroneously inserting an extra space between the NP and the first group.
For NZ, this results in '09 -123 1234', and for other countries it results
in a double space: '02  1234 1234'.
Since the spacing is included in the format specified by the DB,
we should not need to add any additional spacing here.
Fix: do not insert an extra space in formatted numbers
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.

1 participant