Repository navigation
fix: phone numbers from random digits, and DayOfMonth without a space - #106
Merged
Merged
Conversation
Phonenumber, TollFreePhoneNumber and E164PhoneNumber took their digits from RandomInt(1, 10) and RandomInt(1, 9), which give every number of the range once in a random order. So a phone number was a permutation of 1 to 10 (3.6 million possible numbers, the same ten digits in every one) and 47% of them did not follow the numbering plan: 102-593-8147 has an area code that starts with 1. A toll free number came out as (777) 296-317548, nine digits where the doc says (888) 937-7238, and an E.164 number had 13 digits where the doc has 11. The digits are drawn one by one now: the area code and the exchange start with 2 to 9 and are not N11, a toll free number is (888) 937-7238 and an E.164 number is a plus and 11 digits.
DayOfMonthFormat was "_2", which pads the days below 10 with a space (" 4"),
so 29% of the values of DayOfMonth had a leading space. It is "2" now: 4.
Contributor
Changing this will break the output format, though. Not sure where else it's used. What I'm afraid is that if any service uses it for string comparisons, it will break. But since the test isn't breaking, it's probably safe. |
bxcodec
approved these changes
Nov 24, 2026
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.
I ran every generator through validator.js (
isMobilePhone,isEmail,isURL,isIP,isMACAddress,isJWT,isUUID,isISO8601and so on, 3,000 to 30,000 values each). Two things gave wrong values: the phone numbers andDayOfMonth. The rest was fine.Phone numbers
Phonenumber,TollFreePhoneNumberandE164PhoneNumbertook their digits fromRandomInt(1, 10)andRandomInt(1, 9), which return every number of the range once, in a random order. So a phone number was a permutation of 1 to 10 glued together:Phonenumberhas only 3.6 million possible numbers (the digits 1 to 9 once each and a10), 54 of 20,000 came up twice, and 47% do not follow the numbering plan:102-593-8147has an area code that starts with 1 (isMobilePhone(x, "en-US")rejects them).TollFreePhoneNumbercame out as(777) 296-317548: nine digits after the code where the doc says(888) 937-7238. All of them (20,000 of 20,000) had the wrong length.E164PhoneNumberhad 13 digits (+798610152473), the example in the doc has 11 (+27113456789).The digits are drawn one by one now (
randomStringNumber, asChinesePhoneNumberdoes):Phonenumber:201-886-0269. The area code and the exchange start with 2 to 9 and are not N11 (211, 411, 911 and so on are service codes).TollFreePhoneNumber:(888) 937-7238. I kept the 777 and 888 that the tests expect (777 is not a toll free code, the real ones are 800, 833, 844, 855, 866, 877 and 888: say so if you want those).E164PhoneNumber: a plus, the 7 or the 8 that was there and 10 random digits.DayOfMonth
DayOfMonthFormatis"_2", which pads the days below 10 with a space, so 29% of the values (872 of 3,000) were like" 4". It is"2"now, andtime.Parse(DayOfMonthFormat, ...)in the existing tests still works.How it was tested
phone_test.go: 20,000Phonenumberagainst the numbering plan, 20,000 toll free numbers against(888) 937-7238, 20,000 E.164 numbers against a plus and 11 digits, and the digits at the free places of each of them (every digit within 15% of an even share, and few numbers that come up twice). Indatetime_test.go: 3,000 days, all 31 of them and no space. All five fail on master (9,423 of 20,000 phone numbers off the plan, 20,000 of 20,000 toll free and E.164 numbers with the wrong length).Phonenumbervalues (isMobilePhone, en-US) and all 30,000 are different.go test ./...,go vetandgofmtpass. I could not run-raceor golangci-lint here (no C compiler and no linter installed), CI does.