Browse Source

Throw if the phone-context parameter appears before the tel: prefix.

improve-rfc-handling-java
Silvio Brändle 11 months ago
parent
commit
513e5f0839
2 changed files with 5 additions and 3 deletions
  1. +2
    -3
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  2. +3
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

+ 2
- 3
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -3232,9 +3232,8 @@ public class PhoneNumberUtil {
int numberEnd = numberToParse.indexOf(";", numberStart);
if (numberEnd < 0) {
// If there is no semicolon, we assume the rest of the string is the national number.
// This should not happen, since we expect to find a semicolon if there is a phone-context.
numberEnd = numberToParse.length();
throw new NumberParseException(NumberParseException.ErrorType.NOT_A_NUMBER,
"The string supplied did not seem to be a phone number.");
}
String numberPart = numberToParse.substring(numberStart, numberEnd);


+ 3
- 0
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -2954,6 +2954,9 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=3phone");
assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=a-.nz");
assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=a{b}c");
// The phone-context parameter comes before the phone number.
assertThrowsForInvalidPhoneContext(";phone-context=+64;tel:03-331-6005");
}
private void assertThrowsForInvalidPhoneContext(String numberToParse) {


Loading…
Cancel
Save