Skip to content

ISBN verifier: missing edge cases  #1096

Closed
@kytrinyx

Description

@kytrinyx

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions