Content-Length: 365699 | pFad | https://github.com/jquery-validation/jquery-validation/pull/2460

4E Additional: vinUS validation fails on valid vin numbers by wewhite · Pull Request #2460 · jquery-validation/jquery-validation · GitHub
Skip to content

Additional: vinUS validation fails on valid vin numbers #2460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 1, 2022

Conversation

wewhite
Copy link
Contributor

@wewhite wewhite commented Nov 30, 2022

Compare by value and type (===) does not work for this algorithm, as both cd and cdv can be either types at the same time. By comparing by value only (==) cd and cdv can be either integer or string, as a string number will be converted to a number reqardless of type.

Relates to BUG: #2459

Compare by value and type (===) does not work for this algorithm, as both cd and cdv can be either types at the same time.
By comparing by value only (==) cd and cdv can be either integer or string, as a string number will be converted to a number reqardless of type.
Copy link
Member

@bytestream bytestream left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you add a test, and revert the other changes as line 50 (if ( parseInt(cd) === parseInt(cdv) ) {) seems to be the only relevant change.

}
if ( cd === cdv ) {
// cd and cdv can be either integer string
if ( cd == cdv ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think parseInt() should be used instead. For example, (parseInt("X") === parseInt("X")) === false. Any complaint against that?

Suggested change
if ( cd == cdv ) {
if ( parseInt(cd) === parseInt(cdv) ) {

Copy link
Contributor Author

@wewhite wewhite Nov 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that will not work, if string cd ="X" and string cdv="X" should = true.
line 50 could be 'if (+cd === +cdv')' the plus(+) on a string will evaluate it to an int, other wise it is a string.

In reality, the vin check digit in location 8 should be transliterated to a number not a string.
That way the check digit cd and check digit vin cdv will always be a number.

@wewhite
Copy link
Contributor Author

wewhite commented Nov 30, 2022

I've rewritten the for loop, and removed the nested loop, different commit on my branch.
Will create a test.

@wewhite
Copy link
Contributor Author

wewhite commented Dec 1, 2022

Code is better now, replaced nested for loop with an array index lookup.
Created test cases, added to the test/index file, and created a separate additional vinUS.js test file.

@bytestream bytestream changed the title Removed === compare, changed to == Additional: vinUS validation fails on valid vin numbers Dec 1, 2022
@bytestream bytestream merged commit 13b859e into jquery-validation:master Dec 1, 2022
@bytestream
Copy link
Member

Thanks ❤️

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.

Additional validation vinUS fails to validate valid Vehicle Identification Number (VIN).
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/jquery-validation/jquery-validation/pull/2460

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy