fix: select a phone format that can hold the typed digits (NANP 310 numbers were truncated to 7 digits) - #17
Merged
janicduplessis merged 1 commit intoSep 25, 2026
Conversation
NANP country data lists Canada's 7-digit "310-XXXX" service-number format ahead of the 10-digit format for every +1 country. selectFormat returned the first leading-digits match without considering length, and applyFormat then clamped the input to that format's capacity, so any +1 number with area code 310 silently dropped every digit after the seventh. selectFormat now passes over a match whose pattern cannot hold the digits typed so far and continues to the next match, falling back to the widest match so overlong input is still clamped. This mirrors libphonenumber's AsYouTypeFormatter, which re-chooses a format once its template is exhausted. selectFormat moves below getFormatMaxDigits, which it now calls, so the worklet plugin's closure capture never sees a const in its temporal dead zone. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Merged
2 of 6 tasks
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PhoneNumberTransformersilently drops every digit after the seventh for +1 numbers with area code 310 (Los Angeles), so a full 10-digit 310 number can never be entered, in both national mode (country: 'US') and international mode.Cause
The generated NANP country data lists two formats for every +1 country, in this order:
(\d{3})(\d{4})→$1-$2, leading digits310(Canada's 7-digit310-XXXXservice numbers)(\d{3})(\d{3})(\d{4})→($1) $2-$3, leading digits[2-9]selectFormatreturns the first format whoseleadingDigitsmatches and never considers the number of digits typed, andapplyFormatthen clamps the input to that format's capacity viagetFormatMaxDigits. Any national number starting with310is therefore truncated to seven digits:Fix
selectFormatnow passes over a leading-digits match whose pattern cannot hold every digit typed so far and continues to the next match. If every matching format overflows, it falls back to the widest match, so overlong input is still clamped exactly as before (the existing "limits to 10 national digits" test is unchanged). This mirrors libphonenumber'sAsYouTypeFormatter, which re-chooses a format once the current template is exhausted:selectFormatmoves belowgetFormatMaxDigits, which it now calls, so the worklet plugin's eager closure capture never sees aconstin its temporal dead zone.Behaviour only changes when a leading-digits match cannot hold the digits typed so far; previously those digits were dropped. In the bundled data
310is the only prefix whose format shadows a longer one, and every pattern uses plain\d{n}/\d{n,m}groups, so the capacity check is exact.Tests
Added a
formats sharing a leading-digits prefix (NANP 310)block toPhoneNumberTransformer.test.tscovering national and international mode, the genuine 7-digit310-2705case, the 7-to-10-digit transition with cursor position, and the 10-digit cap.yarn test,yarn lint, andyarn format:prettier:checkpass locally.Context
Found via a signup form in Tlon Messenger where users with 310 numbers could not register; we are shipping this as a pnpm patch on 0.4.1 in the meantime (tloncorp/tlon-apps#6613).
🤖 Generated with Claude Code