Skip to content

Fix Turkish ID check digits when the weighted difference is negative - #1073

Open
SashaMIT wants to merge 1 commit into
FakerPHP:1.24from
SashaMIT:codered-tcno-negative-digit
Open

SashaMIT wants to merge 1 commit into
FakerPHP:1.24from
SashaMIT:codered-tcno-negative-digit

Conversation

@SashaMIT

Copy link
Copy Markdown

Summary

  • The tenth digit of a Turkish identification number is (7 * odd positions - even positions) mod 10. PHP keeps the sign of a negative remainder, so the digit was -9 and the two check characters were the string -98.
  • 190909090 checks as 18. The full number 19090909018 was rejected. 19090909019 stays invalid. Existing vectors such as 553006348 / 82 and 10000000146 still pass.
  • The same expression is on 2.0. This pull request targets 1.24, which is the branch current releases come from. Issue Issues with T.C. ID number generation: leading zero and negative tenth digit #966 described the negative digit and was closed by the stale bot without a code change.

Test plan

  • vendor/bin/phpunit --filter PersonTest test/Faker/Provider/tr_TR/PersonTest.php failed on the new vector before the fix (expected '18', actual '-98', and 19090909018 was not valid)
  • After the fix, the same file is 16 tests, 215 assertions

Made with Cursor

PHP keeps the sign of a negative remainder, so the tenth digit was -9 and the number was -98 instead of 18.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants