zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.

Home Page:https://zxing-js.github.io/library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Barcode starting with 0 not detected when EAN13 and UPC A are both enabled

jneuhaus20 opened this issue · comments

I have a barcode starting with '0' that is either EAN13 or UPC A (honestly not sure which one it "really" is, just that it's ambiguous according to the readers.) When EAN13 and UPC_A are both enabled, no barcode is detected.

I tracked it down to the conversion functionality here:

if (ean13MayBeUPCA && canReturnUPCA) {
const rawBytes = result.getRawBytes();
// Transfer the metadata across
const resultUPCA: Result = new Result(
result.getText().substring(1),
rawBytes,
rawBytes.length,
result.getResultPoints(),
BarcodeFormat.UPC_A
);
resultUPCA.putAllMetadata(result.getResultMetadata());
return resultUPCA;
}

The problem is that UPCEANReader doesn't actually set the raw bytes, so rawBytes is set to null at line 98, and the accessor on 103 throws an error, which is caught higher up and converted into NotFoundException.

I tried to fork the demo's StackBlitz for this as the current one is out of date, but there's an unrelated ES5/ES6 issue going on across the packages.

I created PR #456 for this already.

I scan UPC-A Barcode i.e 725272730706 and its detecting EAN_13 with a leading 0 in this barcode i.e 0725272730706

Yeah, the graphical encoding (bars) are literally that (see this great explanation on the two). Basically, US and Canada just don't write the leading 0 under the bars, for historical reasons that are stupid.