diff --git a/Signal/src/ViewControllers/ViewControllerUtils.m b/Signal/src/ViewControllers/ViewControllerUtils.m index 51b33c143..c70168018 100644 --- a/Signal/src/ViewControllers/ViewControllerUtils.m +++ b/Signal/src/ViewControllers/ViewControllerUtils.m @@ -49,10 +49,15 @@ NS_ASSUME_NONNULL_BEGIN NSString *center = insertionText.digitsOnly; // 4. Construct the "raw" new text by concatenating left, center and right. NSString *textAfterChange = [[left stringByAppendingString:center] stringByAppendingString:right]; - // NOTE: We can't ensure that the number does not exceed the maximum length for a e164 phone number, - // 15 digits, per: https://en.wikipedia.org/wiki/E.164 - // because "valid numbers in Germany have been assigned that are longer than this" per: + // 4a. Ensure we don't exceed the maximum length for a e164 phone number, + // 15 digits, per: https://en.wikipedia.org/wiki/E.164 + // + // NOTE: The actual limit is 18, not 15, because of certain invalid phone numbers in Germany. // https://github.com/googlei18n/libphonenumber/blob/master/FALSEHOODS.md + const int kMaxPhoneNumberLength = 18; + if (textAfterChange.length > kMaxPhoneNumberLength) { + textAfterChange = [textAfterChange substringToIndex:kMaxPhoneNumberLength]; + } // 5. Construct the "formatted" new text by inserting a hyphen if necessary. // reformat the phone number, trying to keep the cursor beside the inserted or deleted digit bool isJustDeletion = insertionText.length == 0;