DacoTaco / BarcodeParserBuilder

BarcodeParserBuilder is a .Net ( standard 2.0 & 2.1 ) nuget package to help parse & build barcode strings
https://www.nuget.org/packages/BarcodeParserBuilder
GNU Lesser General Public License v2.1
11 stars 4 forks source link

Bad EAN/UPC barcode being parsed as GS1 #4

Closed warnwar closed 1 year ago

warnwar commented 1 year ago

I think I found one issue with the most recent 0.0.6 version: If I feed a bad EAN/UPC barcode into the parser, it returns it as a GS1 barcode.

Here is my raw barcode string: 300450549108 which is a bad barcode because the checksum digit is wrong

Here is a screenshot of what happens when I parse this: image You can see that this is being identified as a GS1 barcode, but I would still expect that this gets handled as a UPC.

In case it helps any, I also noticed that it does null out the product code: image

DacoTaco commented 1 year ago

hm, that is indeed not good. i suspect the barcode is a EAN/UPC barcode, and not a GS1 (since it lacks the 01 application identifier) ? if so, i suspect the lack of parsing the application identifier 30 is at fault here. i see you have access to see whats in _barcodefields. could you check barcodefield with id "30" ? i suspect it to have "0450549108"

though even if i add 30 processing (which i should), it will fail for this case (invalid AI 08 & no ending ), but it could be a valid GS1 without it. is this a problem for you?

warnwar commented 1 year ago

You are right that this is an EAN/UPC because it's missing the '01' application identifier. It looks like you are also correct about the AI likely causing a problem:

image

I'm not an expert at GS1 parsing, but I would think that if it's lacking the '01' AI then it cannot be valid. What do you think?

DacoTaco commented 1 year ago

ive fixed the 30 AI parsing, and it now forces it to be a field of 1-8 characters long, integers typed. it should help with this case, but is not a correct 'fix'. ive also released version 0.1.0 with said fix (skipped few versions so i can start updating in patches)

i am also no expert, but i think the GS1 specs do not mention some Application Identifiers/fields are required, so you can have a GS1 without a product code. who would be interested in it is a different case, but its within the specs.

this comes from the knowledge that a EAN128/GS128 barcode , in 1D form, can be separated in several parts in which part 1 has the product code and lot number and part 2 has the serial. GS1 and 2D barcodes are an extension of that afaik.

EDIT : i think it is better for your code to check if there is a product code, since youre mostly interested in it

warnwar commented 1 year ago

Understood. I updated my code so I'm checking for a missing product code. If that happens I'm treating it like parsing failed since right now I don't care about any GS1 AIs other than '01'. I'll also be sure to grab the latest version so I'm fully up-to-date. Thanks again for looking into this!

DacoTaco commented 1 year ago

no problem! i love that this improves the project !