Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testNumberLengthAgainstPattern is returning TOO_SHORT when the number of digits is between 7 and 10 #32

Open
jvictorchen opened this issue Sep 2, 2016 · 0 comments

Comments

@jvictorchen
Copy link
Contributor

jvictorchen commented Sep 2, 2016

According to the documentation, if the pattern is suggesting that the number should have length of 7 or 10, and when the number actually has length of 8, this function will return TOO_LONG.

// Helper method to check a number against a particular pattern and
// determine whether it matches, or is too short or too long. Currently,
// if a number pattern suggests that numbers of length 7 and 10 are
// possible, and a number in between these possible lengths is entered,
// such as of length 8, this will return TOO_LONG.

But in the current implementation, it's returning TOO_SHORT.

inds := numberPattern.FindStringIndex(number)
    if len(inds) > 0 && inds[0] == 0 && inds[1] == len(number) {
        if inds[1] == len(number) { // Exact match
            return IS_POSSIBLE
        }
        return TOO_LONG // Matches input start but not end
    }

    return TOO_SHORT // Does not match input start

This leads to a weird behavior of duplicating the last digit when a phone number is hence categorized as too long. For example, +1 951178619 will be parsed and formatted into +1 951-178-6199.

jvictorchen added a commit to jvictorchen/libphonenumber that referenced this issue Sep 2, 2016
ttacon pushed a commit that referenced this issue Sep 5, 2016
* Fix a bug raised in issue #32

See #32 for more details

* Correct the logic in the previous bug fix

* Correct the logic in the previous bug fix

* Add tests for testNumberLengthAgainstPattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant