Skip to content

bug: ITF-14 does not validate provided check digit #67

Description

@productdevbook

Summary

When a 14-digit ITF-14 code is provided (with check digit), src/encoders/itf.ts does not validate that the check digit is correct. It just passes the raw 14 digits through.

Details

export function encodeITF14(text: string): number[] {
  validateDigitsOnly(text);
  let digits: string;
  if (text.length === 13) {
    const nums = text.split("").map(Number);
    const check = calculateCheckDigit(nums);
    digits = text + String(check);
  } else if (text.length === 14) {
    digits = text;  // No validation!
  } else {
    throw new InvalidInputError("ITF-14 requires 13 or 14 digits");
  }
  return encodeITF(digits);
}

When 14 digits are provided, the check digit (last digit) should be verified against the calculated value, similar to how UPC-A does it.

Impact

ITF-14 barcodes with incorrect check digits are silently accepted. These barcodes will fail GS1 verification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions