Closed
Description
Reported by @uranusjr in exercism/exercism#3711.
The original report mentions Rust specifically, but I believe that this is likely a problem with the canonical data.
(Note: for ease of reference I copied the code example into the issue)
They do not ensure implementations check for ISBN length. No tests for strings that’s too short (< 10 digits), and although there are tests for > 10 digits, their checksum results are not 0 to begin with so implementations can get away just adding everything up. Here’s an example.
/// Determines whether the supplied string is a valid ISBN number
pub fn is_valid_isbn(isbn: &str) -> bool {
let mut check = 0;
for (i, c) in isbn.chars().rev().filter(|&c| c != '-').enumerate() {
check += (i as u32 + 1) * match c {
'X' if i == 0 => 10,
c @ '0'...'9' => c.to_digit(10).unwrap(),
_ => { return false; },
}
}
check % 11 == 0
}
Metadata
Metadata
Assignees
Labels
No labels