mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-25 08:37:23 +01:00
Made EIGP114 parsing less strict (#1321)
* Enhance barcode format checking in isFormat06Code Updated isFormat06Code method to handle additional barcode formats for compatibility with older Mouser parts and Eyoyo barcode scanners that don't omit the record separator character * Added tests --------- Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
@@ -254,12 +254,16 @@ readonly class EIGP114BarcodeScanResult implements BarcodeScanResultInterface
|
||||
*/
|
||||
public static function isFormat06Code(string $input): bool
|
||||
{
|
||||
//Code must begin with [)><RS>06<GS>
|
||||
if(!str_starts_with($input, "[)>\u{1E}06\u{1D}")){
|
||||
return false;
|
||||
//Code should begin with [)><RS>06<GS> as per the standard
|
||||
if(!str_starts_with($input, "[)>\u{1E}06\u{1D}")
|
||||
// some codes don't contain record separators
|
||||
&& !str_starts_with($input, "[)>06\u{1D}")
|
||||
// This is found on old Mouser parts
|
||||
&& !str_starts_with($input, ">[)>06\u{1D}"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Digikey does not put a trailer onto the barcode, so we just check for the header
|
||||
//Digikey and Mouser don't put a trailer onto the barcode, so we just check for the header
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -93,6 +93,13 @@ final class EIGP114BarcodeScanResultTest extends TestCase
|
||||
|
||||
//Valid code (digikey, without trailer)
|
||||
$this->assertTrue(EIGP114BarcodeScanResult::isFormat06Code("[)>\x1e06\x1dPQ1045-ND\x1d1P364019-01\x1d30PQ1045-ND\x1dK12432 TRAVIS FOSS P\x1d1K85732873\x1d10K103332956\x1d9D231013\x1d1TQJ13P\x1d11K1\x1d4LTW\x1dQ3\x1d11ZPICK\x1d12Z7360988\x1d13Z999999\x1d20Z0000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
|
||||
|
||||
//Valid code (without record separator)
|
||||
$this->assertTrue(EIGP114BarcodeScanResult::isFormat06Code("[)>06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04"));
|
||||
|
||||
//Old mouser format
|
||||
$this->assertTrue(EIGP114BarcodeScanResult::isFormat06Code(">[)>06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04"));
|
||||
|
||||
}
|
||||
|
||||
public function testParseFormat06CodeInvalid(): void
|
||||
@@ -101,6 +108,32 @@ final class EIGP114BarcodeScanResultTest extends TestCase
|
||||
EIGP114BarcodeScanResult::parseFormat06Code('');
|
||||
}
|
||||
|
||||
public function testParseWithoutRecordSeparator(): void
|
||||
{
|
||||
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04");
|
||||
$this->assertSame([
|
||||
'P' => '596-777A1-ND',
|
||||
'1P' => 'XAF4444',
|
||||
'Q' => '3',
|
||||
'10D' => '1452',
|
||||
'1T' => 'BF1103',
|
||||
'4L' => 'US',
|
||||
], $barcode->data);
|
||||
}
|
||||
|
||||
public function testParseOldMouserFormat(): void
|
||||
{
|
||||
$barcode = EIGP114BarcodeScanResult::parseFormat06Code(">[)>06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04");
|
||||
$this->assertSame([
|
||||
'P' => '596-777A1-ND',
|
||||
'1P' => 'XAF4444',
|
||||
'Q' => '3',
|
||||
'10D' => '1452',
|
||||
'1T' => 'BF1103',
|
||||
'4L' => 'US',
|
||||
], $barcode->data);
|
||||
}
|
||||
|
||||
public function testParseFormat06Code(): void
|
||||
{
|
||||
$barcode = EIGP114BarcodeScanResult::parseFormat06Code("[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04");
|
||||
|
||||
Reference in New Issue
Block a user