trim input in IBANValidator.validate#411
Conversation
|
Sorry, but I don't think this is a good idea. The purpose of validation is to check the data that is passed to it. If a caller passes an IBAN with leading or trailing spaces, and the result is success, then the caller should be able to expect that the value can be used as is when passing the data to another method which expects an actual IBAN without any spaces. Any trimming needs to be done by the caller. |
|
Fair enough, that's a reasonable line to draw. The contract argument holds: if validate() trims and returns VALID, a caller could quite reasonably treat the string it handed in as a clean IBAN and pass it on with the whitespace still attached, which is worse than a clear rejection. Leaving normalisation to the caller keeps the status honest about exactly what was given. I'll leave this closed. Cheers for taking a look. |
Noticed while validating IBANs read line by line out of a file: a value with a trailing newline came back INVALID_LENGTH and one with a leading space UNKNOWN_COUNTRY, although both validate once the surrounding whitespace is stripped.
Trimmed once at the top of validate and ran the country lookup, length, pattern and check digit against that value; the null path is unchanged as getValidator already tolerates null.
mvn; that'smvnon the command line by itself.