Claudio Nave (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiNGQ0ZjRhNGJlY...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1945?atlOrigin=eyJpIjoiNGQ0ZjRh...
) HV-1945 (
https://hibernate.atlassian.net/browse/HV-1945?atlOrigin=eyJpIjoiNGQ0ZjRh...
) @LuhnCheck with endIndex and checkDigitIndex equals seems wrong (
https://hibernate.atlassian.net/browse/HV-1945?atlOrigin=eyJpIjoiNGQ0ZjRh...
)
Issue Type: Bug Affects Versions: 8.0.0.Final Assignee: Unassigned Components:
documentation, validators Created: 11/Apr/2023 14:06 PM Priority: Major Reporter: Claudio
Nave (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
Hi,
I’m working on a project that needs to generate random data that passes the Hibernate
validation.
The documentation for the checkDigitIndex field of the @LuhnCheck annotation states that
The index of the check digit in the input. Per default it is assumed that
the check digit is the last digit of the specified range. If set, the
digit at the specified index is used. If set the following must hold true:
checkDigitIndex > 0 && (checkDigitIndex < startIndex || checkDigitIndex
>=
endIndex.
So it’s possible that checkDigitIndex == endIndex, but I don’t think to understand the
logic of the current implementation of this case.
For me the checkDigitIndex being equal to the endIndex should mean that the digit at
endIndex position is considered the check digit, but not part of the number that is being
checked. To clarifiy a bit if I have a string “12345” with endIndex = 4 and
checkDigitIndex = 4 the logical approach for me is to do luhnCheckDigit(1234) == 5. But
the current implementation is much more literal and uses the checkDigitIndex as both the
check digit and part of the number being validated luhnCheckDigit(12345) = 5. This is
technically correct but it doesn’t seem quite right.
Considering that if checkDigitIndex is not manually set the check digit is assumed to be
the last digit of the sequence, but in that case the last digit of the sequence is
excluded from the luhnCheckDigit computation. So for example the same string “12345” with
only endIndex = 4 behaves like it should with luhnCheckDigit(1234) = 5.
It seems to me that something is off with all of this. The case of checkDigitIndex ==
endIndex should be handled in a similar way to when checkDigitIndex isn’t specified and
it’s assumed to be the last digit.
I can help providing a PR for this if you want.
Bye!
(
https://hibernate.atlassian.net/browse/HV-1945#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1945#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:9ff53d8 )