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! |