html5-qrcode icon indicating copy to clipboard operation
html5-qrcode copied to clipboard

Barcode beginning with 0 not recognised

Open sam-the-programmer opened this issue 2 years ago • 6 comments

Describe the bug Any barcode tried that begins with a 0 does not get scanned i.e. it is registered and returned by the api.

To Reproduce Steps to reproduce the behavior:

  1. Try scan a barcode with the scanner, e.g. this one
  2. It won't work (it starts with a 0) - this is consistent amongst all the barcodes (EAN-13s and UPCs) I tried that began with a 0.

Expected behavior Returns the barcode number.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: MS Edge
  • Version: MS Edge Version 104.0.1293.47 (Official build) (64-bit)

Additional context None

sam-the-programmer avatar Aug 10 '22 18:08 sam-the-programmer

I think there is a bug here

when EAN13 format coding starts from 0, the code will continue to process. But i.getRawBytes() is null.

                    decodeRow(t, e, r) {
                        for (let n of this.readers)
                            try {
                                const i = n.decodeRow(t, e, r)
                                  , o = i.getBarcodeFormat() === k.EAN_13 && "0" === i.getText().charAt(0)
                                  , s = null == r ? null : r.get(E.POSSIBLE_FORMATS)
                                  , a = null == s || s.includes(k.UPC_A);
                                if (o && a) {
                                    const t = i.getRawBytes() 
//i.getRawBytes() always is null
                                      , e = new F(i.getText().substring(1),t,t.length,i.getResultPoints(),k.UPC_A);
                                    return e.putAllMetadata(i.getResultMetadata()),
                                    e
                                }
                                return i
                            } catch (t) {}
                        throw new y
                    }

I can't find the code that assigns values to variables m.rawBytes in functions n.decodeRow.

                    decodeRow(t, e, r) {
                        let n = pt.findStartGuardPattern(e)
                          , i = null == r ? null : r.get(E.NEED_RESULT_POINT_CALLBACK);
                        if (null != i) {
                            const e = new nt((n[0] + n[1]) / 2,t);
                            i.foundPossibleResultPoint(e)
                        }
                        let o = this.decodeMiddle(e, n, this.decodeRowStringBuffer)
                          , s = o.rowOffset
                          , a = o.resultString;
                        if (null != i) {
                            const e = new nt(s,t);
                            i.foundPossibleResultPoint(e)
                        }
                        let l = pt.decodeEnd(e, s);
                        if (null != i) {
                            const e = new nt((l[0] + l[1]) / 2,t);
                            i.foundPossibleResultPoint(e)
                        }
                        let h = l[1]
                          , u = h + (h - l[0]);
                        if (u >= e.getSize() || !e.isRange(h, u, !1))
                            throw new y;
                        let d = a.toString();
                        if (d.length < 8)
                            throw new C;
                        if (!pt.checkChecksum(d))
                            throw new c;
                        let g = (n[1] + n[0]) / 2
                          , f = (l[1] + l[0]) / 2
                          , w = this.getBarcodeFormat()
                          , A = [new nt(g,t), new nt(f,t)]
                          , m = new F(d,null,0,A,w,(new Date).getTime())
                          , I = 0;
                        try {
                            let r = _t.decodeRow(t, e, l[1]);
                            m.putMetadata(X.UPC_EAN_EXTENSION, r.getText()),
                            m.putAllMetadata(r.getResultMetadata()),
                            m.addResultPoints(r.getResultPoints()),
                            I = r.getText().length
                        } catch (t) {}
                        let _ = null == r ? null : r.get(E.ALLOWED_EAN_EXTENSIONS);
                        if (null != _) {
                            let t = !1;
                            for (let e in _)
                                if (I.toString() === e) {
                                    t = !0;
                                    break
                                }
                            if (!t)
                                throw new y
                        }
                        return w === k.EAN_13 || k.UPC_A,m
                    }

fixed return w === k.EAN_13 || k.UPC_A, m.rawBytes = e, m

liushengqi000 avatar Sep 03 '22 13:09 liushengqi000

Is this closable if this code is updated?

sam-the-programmer avatar Sep 03 '22 14:09 sam-the-programmer

Is this closable if this code is updated?

I'm not sure because I haven't looked through all the code. After adding the patch, it works normally on my computer.

liushengqi000 avatar Sep 03 '22 15:09 liushengqi000

Ok. Have you commited this to the repo

sam-the-programmer avatar Sep 03 '22 16:09 sam-the-programmer

Ok. Have you commited this to the repo

No, I'm not familiar with TS. Moreover, the main code segment is in zxingJS/library/SRC/core/one/upceanreader.ts I don't know how to fix it in TS code

https://github.com/mebjas/html5-qrcode/issues/361 https://github.com/zxing-js/library/issues/457

liushengqi000 avatar Sep 03 '22 16:09 liushengqi000

Do we know when this is going to be fixed ? I use the unpack version so cant change the file ? Its so annoying, reslly nice package thou works very well apart from this

WayneFellows avatar Sep 17 '22 08:09 WayneFellows

Please track progress on this issue at https://github.com/mebjas/html5-qrcode/issues/605

mebjas avatar Nov 16 '22 15:11 mebjas

Also duplicate of https://github.com/mebjas/html5-qrcode/issues/361

Closing this one.

mebjas avatar Nov 16 '22 15:11 mebjas