From b23e86e40894b1417a492e94fa463e3db55ff41a Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 27 Oct 2024 16:11:06 +0300 Subject: [PATCH 1/2] Bump version to 8.13.48 --- README.md | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 911da70c..743b8567 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ repositories { } dependencies { - implementation 'io.michaelrocks:libphonenumber-android:8.13.47' + implementation 'io.michaelrocks:libphonenumber-android:8.13.48' } ``` @@ -63,5 +63,5 @@ License limitations under the License. [1]: https://github.com/googlei18n/libphonenumber - [2]: http://www.methodscount.com/?lib=com.googlecode.libphonenumber%3Alibphonenumber%3A8.13.47 + [2]: http://www.methodscount.com/?lib=com.googlecode.libphonenumber%3Alibphonenumber%3A8.13.48 [3]: http://blog.nimbledroid.com/2016/04/06/slow-ClassLoader.getResourceAsStream.html diff --git a/build.gradle b/build.gradle index 68ec9fbf..8ef52db2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { group = 'io.michaelrocks' - version = '8.13.47' + version = '8.13.48' ext.projectCompileSdkVersion = 35 ext.projectBuildToolsVersion = '35.0.0' From da5074f5887ae86ce257f8389cdf108442d56f50 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Sun, 27 Oct 2024 16:22:07 +0300 Subject: [PATCH 2/2] Merge code and metadata changes from --- .../android/data/PhoneNumberMetadataProto_DE | Bin 3181 -> 3183 bytes .../android/data/PhoneNumberMetadataProto_SG | Bin 995 -> 999 bytes .../android/data/PhoneNumberMetadataProto_UG | Bin 668 -> 668 bytes .../android/data/PhoneNumberMetadataProto_WF | Bin 453 -> 474 bytes .../source/MultiFileModeFileNameProvider.java | 22 +++++++++++++++--- .../CountryCodeToRegionCodeMapForTesting.java | 2 +- .../android/PhoneNumberUtilTest.java | 22 +++++++++--------- .../libphonenumber/android/RegionCode.java | 14 +++++------ .../android/ShortNumberInfoTest.java | 20 ++++++++-------- .../MultiFileModeFileNameProviderTest.java | 11 +++++++++ .../android/data/PhoneNumberMetadataProto_DE | Bin 3181 -> 3183 bytes .../android/data/PhoneNumberMetadataProto_SG | Bin 995 -> 999 bytes .../android/data/PhoneNumberMetadataProto_UG | Bin 668 -> 668 bytes .../android/data/PhoneNumberMetadataProto_WF | Bin 453 -> 474 bytes 14 files changed, 59 insertions(+), 32 deletions(-) diff --git a/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_DE b/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_DE index be51fb2a2726bfef51eef98cc196899353219780..311b564a6af4d60b0a611d5480c2c0b4714e48ed 100644 GIT binary patch delta 88 zcmaDW@m^wsKC`BSp;@$nk#THHO0~I;MQx3thP{=kv7teYd9;D9skyEtP(~9dX*M~G lc_Vuj0|N_#q0weOmVe9;j*01JVUB;yEag$=wUb48A^>J47zY3V delta 86 zcmaDa@m6AkKC`-=p{cQhP{j!efv%~!u4SwyP|94#VsZrY kMs`D^Dh37?hRp&j|CrfLOd%Xmj(^N7=C$P!lf`)=04}8$NdN!< diff --git a/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_SG b/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_SG index 2d2ed2446c68fdd9ded07682cfb6816f3d1d286c..bc5892e67fa0a98204efaa58a0cb3a642543fc9f 100644 GIT binary patch delta 32 ocmaFN{+yk2&07Z6Dh3ATdlNb5Fa}RtX3ZLHplcMn@ew040J-W4x&QzG delta 28 kcmaFP{+OL}&07Z6Dh3ATTN63wF#1niX3c1{@fjmC0FogIod5s; diff --git a/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_UG b/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_UG index 3c9102fbdcdf4f5aa3d337a374fd016cf42eb655..e652952ba099b2d4c3bd53b8b707fa234b39649f 100644 GIT binary patch delta 14 VcmbQkI)`-w2P31|W=_V*i~t>`1B3to delta 14 VcmbQkI)`-w2P32DW=_V*i~t>=1A_nn diff --git a/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_WF b/library/src/main/assets/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_WF index 79c23086a4d36c6c42a43e6e2d9ff6b8dfb299a3..1f75adeca993c4bbda7097c2793dd3f7e1062a20 100644 GIT binary patch delta 93 zcmX@ge2dv&&07Z6Dh39|iwr=5k&!`O!`{lopvK&&#v&%A+N4$!Ox8qOSjGZbrnM6d rHgYgBa9Kth8OKg66k)S8GBh$anRrodGB0B>8(XxAxvu5pRz?Q^s$&^s delta 73 zcmcb`e3aQ>&07Z6Dh39|Jq$pCk&!`O!`{lopvK%tGbW|lq_)NaNSW3G1%b42t)~4% YgN+jp%S{$$Y-DAPHZixDJd4o*0O6Vx;{X5v diff --git a/library/src/main/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProvider.java b/library/src/main/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProvider.java index 66921115..3aa17d4d 100644 --- a/library/src/main/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProvider.java +++ b/library/src/main/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProvider.java @@ -17,7 +17,6 @@ package io.michaelrocks.libphonenumber.android.metadata.source; -import java.util.regex.Pattern; /** * {@link PhoneMetadataFileNameProvider} implementation which appends key as a suffix to the @@ -26,7 +25,6 @@ public final class MultiFileModeFileNameProvider implements PhoneMetadataFileNameProvider { private final String phoneMetadataFileNamePrefix; - private static final Pattern ALPHANUMERIC = Pattern.compile("^[\\p{L}\\p{N}]+$"); public MultiFileModeFileNameProvider(String phoneMetadataFileNameBase) { this.phoneMetadataFileNamePrefix = phoneMetadataFileNameBase + "_"; @@ -35,9 +33,27 @@ public MultiFileModeFileNameProvider(String phoneMetadataFileNameBase) { @Override public String getFor(Object key) { String keyAsString = key.toString(); - if (!ALPHANUMERIC.matcher(keyAsString).matches()) { + if (!isAlphanumeric(keyAsString)) { throw new IllegalArgumentException("Invalid key: " + keyAsString); } return phoneMetadataFileNamePrefix + key; } + + private boolean isAlphanumeric(String key) { + if (key == null || key.length() == 0) { + return false; + } + // String#length doesn't actually return the number of + // code points in the String, it returns the number + // of char values. + int size = key.length(); + for (int charIdx = 0; charIdx < size; ) { + final int codePoint = key.codePointAt(charIdx); + if (!Character.isLetterOrDigit(codePoint)) { + return false; + } + charIdx += Character.charCount(codePoint); + } + return true; + } } diff --git a/library/src/test/java/io/michaelrocks/libphonenumber/android/CountryCodeToRegionCodeMapForTesting.java b/library/src/test/java/io/michaelrocks/libphonenumber/android/CountryCodeToRegionCodeMapForTesting.java index f47f8829..5637e831 100644 --- a/library/src/test/java/io/michaelrocks/libphonenumber/android/CountryCodeToRegionCodeMapForTesting.java +++ b/library/src/test/java/io/michaelrocks/libphonenumber/android/CountryCodeToRegionCodeMapForTesting.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Libphonenumber Authors + * Copyright (C) 2011 The Libphonenumber Authors * Copyright (C) 2022 Michael Rozumyanskiy * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/library/src/test/java/io/michaelrocks/libphonenumber/android/PhoneNumberUtilTest.java b/library/src/test/java/io/michaelrocks/libphonenumber/android/PhoneNumberUtilTest.java index 24cac36b..2051362f 100644 --- a/library/src/test/java/io/michaelrocks/libphonenumber/android/PhoneNumberUtilTest.java +++ b/library/src/test/java/io/michaelrocks/libphonenumber/android/PhoneNumberUtilTest.java @@ -417,7 +417,7 @@ public void testGetExampleNumber() { // We have data for the US, but no data for VOICEMAIL, so return null. assertNull(phoneUtil.getExampleNumberForType(RegionCode.US, PhoneNumberType.VOICEMAIL)); // CS is an invalid region, so we have no data for it. - assertNull(phoneUtil.getExampleNumberForType(RegionCode.CS, PhoneNumberType.MOBILE)); + assertNull(phoneUtil.getExampleNumberForType("CS", PhoneNumberType.MOBILE)); // RegionCode 001 is reserved for supporting non-geographical country calling code. We don't // support getting an example number for it with this method. assertNull(phoneUtil.getExampleNumber(RegionCode.UN001)); @@ -427,7 +427,7 @@ public void testGetInvalidExampleNumber() { // RegionCode 001 is reserved for supporting non-geographical country calling codes. We don't // support getting an invalid example number for it with getInvalidExampleNumber. assertNull(phoneUtil.getInvalidExampleNumber(RegionCode.UN001)); - assertNull(phoneUtil.getInvalidExampleNumber(RegionCode.CS)); + assertNull(phoneUtil.getInvalidExampleNumber("CS")); PhoneNumber usInvalidNumber = phoneUtil.getInvalidExampleNumber(RegionCode.US); assertEquals(1, usInvalidNumber.getCountryCode()); assertFalse(usInvalidNumber.getNationalNumber() == 0); @@ -660,7 +660,7 @@ public void testFormatOutOfCountryWithInvalidRegion() { // AQ/Antarctica isn't a valid region code for phone number formatting, // so this falls back to intl formatting. assertEquals("+1 650 253 0000", - phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.AQ)); + phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, "AQ")); // For region code 001, the out-of-country format always turns into the international format. assertEquals("+1 650 253 0000", phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.UN001)); @@ -737,7 +737,7 @@ public void testFormatOutOfCountryKeepingAlphaChars() { phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.SG)); // Testing the case of calling from a non-supported region. assertEquals("+61 1-800-SIX-FLAG", - phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ)); + phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, "AQ")); // Testing the case with an invalid country calling code. alphaNumericNumber.setCountryCode(0).setNationalNumber(18007493524L) @@ -756,7 +756,7 @@ public void testFormatOutOfCountryKeepingAlphaChars() { alphaNumericNumber.setCountryCode(1).setNationalNumber(80749L).setRawInput("180-SIX"); // No country-code stripping can be done since the number is invalid. assertEquals("+1 180-SIX", - phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ)); + phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, "AQ")); } public void testFormatWithCarrierCode() { @@ -822,12 +822,12 @@ public void testFormatNumberForMobileDialing() { assertEquals("030123456", phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.DE, false)); assertEquals("+4930123456", - phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.CH, false)); + phoneUtil.formatNumberForMobileDialing(DE_NUMBER, "CH", false)); PhoneNumber deNumberWithExtn = new PhoneNumber().mergeFrom(DE_NUMBER).setExtension("1234"); assertEquals("030123456", phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, RegionCode.DE, false)); assertEquals("+4930123456", - phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, RegionCode.CH, false)); + phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, "CH", false)); // US toll free numbers are marked as noInternationalDialling in the test metadata for testing // purposes. For such numbers, we expect nothing to be returned when the region code is not the @@ -1338,7 +1338,7 @@ public void testGetCountryCodeForRegion() { assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.ZZ)); assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.UN001)); // CS is already deprecated so the library doesn't support it. - assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.CS)); + assertEquals(0, phoneUtil.getCountryCodeForRegion("CS")); } public void testGetNationalDiallingPrefixForRegion() { @@ -1355,7 +1355,7 @@ public void testGetNationalDiallingPrefixForRegion() { assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.ZZ, false)); assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.UN001, false)); // CS is already deprecated so the library doesn't support it. - assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.CS, false)); + assertEquals(null, phoneUtil.getNddPrefixForRegion("CS", false)); } public void testIsNANPACountry() { @@ -2432,7 +2432,7 @@ public void testFailedParseOnInvalidNumbers() { } try { String someNumber = "123 456 7890"; - phoneUtil.parse(someNumber, RegionCode.CS); + phoneUtil.parse(someNumber, "CS"); fail("Deprecated region code not allowed: should fail."); } catch (NumberParseException e) { // Expected this exception. @@ -2856,7 +2856,7 @@ public void testParseAndKeepRaw() throws Exception { // Invalid region code supplied. try { - phoneUtil.parseAndKeepRawInput("123 456 7890", RegionCode.CS); + phoneUtil.parseAndKeepRawInput("123 456 7890", "CS"); fail("Deprecated region code not allowed: should fail."); } catch (NumberParseException e) { // Expected this exception. diff --git a/library/src/test/java/io/michaelrocks/libphonenumber/android/RegionCode.java b/library/src/test/java/io/michaelrocks/libphonenumber/android/RegionCode.java index fa4b0bef..662514c1 100644 --- a/library/src/test/java/io/michaelrocks/libphonenumber/android/RegionCode.java +++ b/library/src/test/java/io/michaelrocks/libphonenumber/android/RegionCode.java @@ -15,6 +15,10 @@ * limitations under the License. */ +/* This file is automatically generated by {@link BuildMetadataProtoFromXml}. + * Please don't modify it directly. + */ + package io.michaelrocks.libphonenumber.android; /** @@ -27,7 +31,6 @@ final class RegionCode { static final String AE = "AE"; static final String AM = "AM"; static final String AO = "AO"; - static final String AQ = "AQ"; static final String AR = "AR"; static final String AU = "AU"; static final String BB = "BB"; @@ -35,31 +38,28 @@ final class RegionCode { static final String BS = "BS"; static final String BY = "BY"; static final String CA = "CA"; - static final String CH = "CH"; - static final String CL = "CL"; + static final String CC = "CC"; static final String CN = "CN"; static final String CO = "CO"; - static final String CS = "CS"; static final String CX = "CX"; static final String DE = "DE"; static final String FR = "FR"; static final String GB = "GB"; - static final String HU = "HU"; + static final String GG = "GG"; static final String IT = "IT"; static final String JP = "JP"; static final String KR = "KR"; static final String MX = "MX"; static final String NZ = "NZ"; - static final String PG = "PG"; static final String PL = "PL"; static final String RE = "RE"; static final String RU = "RU"; static final String SE = "SE"; static final String SG = "SG"; + static final String TA = "TA"; static final String US = "US"; static final String UZ = "UZ"; static final String YT = "YT"; - static final String ZW = "ZW"; // Official code for the unknown region. static final String ZZ = "ZZ"; } diff --git a/library/src/test/java/io/michaelrocks/libphonenumber/android/ShortNumberInfoTest.java b/library/src/test/java/io/michaelrocks/libphonenumber/android/ShortNumberInfoTest.java index e7accae3..9228938c 100644 --- a/library/src/test/java/io/michaelrocks/libphonenumber/android/ShortNumberInfoTest.java +++ b/library/src/test/java/io/michaelrocks/libphonenumber/android/ShortNumberInfoTest.java @@ -244,14 +244,14 @@ public void testConnectsToEmergencyNumberLongNumber_BR() { } public void testConnectsToEmergencyNumber_CL() { - assertTrue(shortInfo.connectsToEmergencyNumber("131", RegionCode.CL)); - assertTrue(shortInfo.connectsToEmergencyNumber("133", RegionCode.CL)); + assertTrue(shortInfo.connectsToEmergencyNumber("131", "CL")); + assertTrue(shortInfo.connectsToEmergencyNumber("133", "CL")); } public void testConnectsToEmergencyNumberLongNumber_CL() { // Chilean emergency numbers don't work when additional digits are appended. - assertFalse(shortInfo.connectsToEmergencyNumber("1313", RegionCode.CL)); - assertFalse(shortInfo.connectsToEmergencyNumber("1330", RegionCode.CL)); + assertFalse(shortInfo.connectsToEmergencyNumber("1313", "CL")); + assertFalse(shortInfo.connectsToEmergencyNumber("1330", "CL")); } public void testConnectsToEmergencyNumber_AO() { @@ -263,9 +263,9 @@ public void testConnectsToEmergencyNumber_AO() { public void testConnectsToEmergencyNumber_ZW() { // Zimbabwe doesn't have any metadata in the test metadata. - assertFalse(shortInfo.connectsToEmergencyNumber("911", RegionCode.ZW)); - assertFalse(shortInfo.connectsToEmergencyNumber("01312345", RegionCode.ZW)); - assertFalse(shortInfo.connectsToEmergencyNumber("0711234567", RegionCode.ZW)); + assertFalse(shortInfo.connectsToEmergencyNumber("911", "ZW")); + assertFalse(shortInfo.connectsToEmergencyNumber("01312345", "ZW")); + assertFalse(shortInfo.connectsToEmergencyNumber("0711234567", "ZW")); } public void testIsEmergencyNumber_US() { @@ -318,9 +318,9 @@ public void testIsEmergencyNumber_AO() { public void testIsEmergencyNumber_ZW() { // Zimbabwe doesn't have any metadata in the test metadata. - assertFalse(shortInfo.isEmergencyNumber("911", RegionCode.ZW)); - assertFalse(shortInfo.isEmergencyNumber("01312345", RegionCode.ZW)); - assertFalse(shortInfo.isEmergencyNumber("0711234567", RegionCode.ZW)); + assertFalse(shortInfo.isEmergencyNumber("911", "ZW")); + assertFalse(shortInfo.isEmergencyNumber("01312345", "ZW")); + assertFalse(shortInfo.isEmergencyNumber("0711234567", "ZW")); } public void testEmergencyNumberForSharedCountryCallingCode() { diff --git a/library/src/test/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProviderTest.java b/library/src/test/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProviderTest.java index 92e352ac..ece344e2 100644 --- a/library/src/test/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProviderTest.java +++ b/library/src/test/java/io/michaelrocks/libphonenumber/android/metadata/source/MultiFileModeFileNameProviderTest.java @@ -44,4 +44,15 @@ public void run() { } }); } + + public void getFor_shouldThrowExceptionForEmptyKey() { + assertThrows( + IllegalArgumentException.class, + new ThrowingRunnable() { + @Override + public void run() { + metadataFileNameProvider.getFor(""); + } + }); + } } diff --git a/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_DE b/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_DE index be51fb2a2726bfef51eef98cc196899353219780..311b564a6af4d60b0a611d5480c2c0b4714e48ed 100644 GIT binary patch delta 88 zcmaDW@m^wsKC`BSp;@$nk#THHO0~I;MQx3thP{=kv7teYd9;D9skyEtP(~9dX*M~G lc_Vuj0|N_#q0weOmVe9;j*01JVUB;yEag$=wUb48A^>J47zY3V delta 86 zcmaDa@m6AkKC`-=p{cQhP{j!efv%~!u4SwyP|94#VsZrY kMs`D^Dh37?hRp&j|CrfLOd%Xmj(^N7=C$P!lf`)=04}8$NdN!< diff --git a/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_SG b/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_SG index 2d2ed2446c68fdd9ded07682cfb6816f3d1d286c..bc5892e67fa0a98204efaa58a0cb3a642543fc9f 100644 GIT binary patch delta 32 ocmaFN{+yk2&07Z6Dh3ATdlNb5Fa}RtX3ZLHplcMn@ew040J-W4x&QzG delta 28 kcmaFP{+OL}&07Z6Dh3ATTN63wF#1niX3c1{@fjmC0FogIod5s; diff --git a/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_UG b/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_UG index 3c9102fbdcdf4f5aa3d337a374fd016cf42eb655..e652952ba099b2d4c3bd53b8b707fa234b39649f 100644 GIT binary patch delta 14 VcmbQkI)`-w2P31|W=_V*i~t>`1B3to delta 14 VcmbQkI)`-w2P32DW=_V*i~t>=1A_nn diff --git a/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_WF b/library/src/test/resources/io/michaelrocks/libphonenumber/android/data/PhoneNumberMetadataProto_WF index 79c23086a4d36c6c42a43e6e2d9ff6b8dfb299a3..1f75adeca993c4bbda7097c2793dd3f7e1062a20 100644 GIT binary patch delta 93 zcmX@ge2dv&&07Z6Dh39|iwr=5k&!`O!`{lopvK&&#v&%A+N4$!Ox8qOSjGZbrnM6d rHgYgBa9Kth8OKg66k)S8GBh$anRrodGB0B>8(XxAxvu5pRz?Q^s$&^s delta 73 zcmcb`e3aQ>&07Z6Dh39|Jq$pCk&!`O!`{lopvK%tGbW|lq_)NaNSW3G1%b42t)~4% YgN+jp%S{$$Y-DAPHZixDJd4o*0O6Vx;{X5v