Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5214376d authored by Ficus Kirkpatrick's avatar Ficus Kirkpatrick
Browse files

Stop the NANP number formatter from putting dashes in shortcodes.

This changes the result of PhoneNumberUtils.formatNumber("46645") from
"466-45" to "46645".
parent 3246c224
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1003,6 +1003,7 @@ public class PhoneNumberUtils
     * as:
     *
     * <p><code>
     * xxxxx
     * xxx-xxxx
     * xxx-xxx-xxxx
     * 1-xxx-xxx-xxxx
@@ -1016,7 +1017,11 @@ public class PhoneNumberUtils
        if (length > "+1-nnn-nnn-nnnn".length()) {
            // The string is too long to be formatted
            return;
        } else if (length <= 5) {
            // The string is either a shortcode or too short to be formatted
            return;
        }

        CharSequence saved = text.subSequence(0, length);

        // Strip the dashes first, as we're going to add them back
+5 −0
Original line number Diff line number Diff line
@@ -302,6 +302,11 @@ public class PhoneNumberUtilsTest extends TestCase {
        number.append("800-55512");
        PhoneNumberUtils.formatNanpNumber(number);
        assertEquals("800-555-12", number.toString());

        number.clear();
        number.append("46645");
        PhoneNumberUtils.formatNanpNumber(number);
        assertEquals("46645", number.toString());
    }

    @SmallTest