File tree Expand file tree Collapse file tree 2 files changed +42
-5
lines changed
src/Services/LabelSystem/BarcodeScanner
tests/Services/LabelSystem/BarcodeScanner Expand file tree Collapse file tree 2 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -254,12 +254,16 @@ public function guessBarcodeVendor(): ?string
254254 */
255255 public static function isFormat06Code (string $ input ): bool
256256 {
257- //Code must begin with [)><RS>06<GS>
258- if (!str_starts_with ($ input , "[)> \u{1E}06 \u{1D}" )){
259- return false ;
257+ //Code should begin with [)><RS>06<GS> as per the standard
258+ if (!str_starts_with ($ input , "[)> \u{1E}06 \u{1D}" )
259+ // some codes don't contain record separators
260+ && !str_starts_with ($ input , "[)>06 \u{1D}" )
261+ // This is found on old Mouser parts
262+ && !str_starts_with ($ input , ">[)>06 \u{1D}" ))
263+ {
264+ return false ;
260265 }
261-
262- //Digikey does not put a trailer onto the barcode, so we just check for the header
266+ //Digikey and Mouser don't put a trailer onto the barcode, so we just check for the header
263267
264268 return true ;
265269 }
Original file line number Diff line number Diff line change @@ -93,6 +93,13 @@ public function testIsFormat06Code(): void
9393
9494 //Valid code (digikey, without trailer)
9595 $ 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 " ));
96+
97+ //Valid code (without record separator)
98+ $ this ->assertTrue (EIGP114BarcodeScanResult::isFormat06Code ("[)>06 \x1DP596-777A1-ND \x1D1PXAF4444 \x1DQ3 \x1D10D1452 \x1D1TBF1103 \x1D4LUS \x1E\x04" ));
99+
100+ //Old mouser format
101+ $ this ->assertTrue (EIGP114BarcodeScanResult::isFormat06Code (">[)>06 \x1DP596-777A1-ND \x1D1PXAF4444 \x1DQ3 \x1D10D1452 \x1D1TBF1103 \x1D4LUS \x1E\x04" ));
102+
96103 }
97104
98105 public function testParseFormat06CodeInvalid (): void
@@ -101,6 +108,32 @@ public function testParseFormat06CodeInvalid(): void
101108 EIGP114BarcodeScanResult::parseFormat06Code ('' );
102109 }
103110
111+ public function testParseWithoutRecordSeparator (): void
112+ {
113+ $ barcode = EIGP114BarcodeScanResult::parseFormat06Code ("[)>06 \x1DP596-777A1-ND \x1D1PXAF4444 \x1DQ3 \x1D10D1452 \x1D1TBF1103 \x1D4LUS \x1E\x04" );
114+ $ this ->assertSame ([
115+ 'P ' => '596-777A1-ND ' ,
116+ '1P ' => 'XAF4444 ' ,
117+ 'Q ' => '3 ' ,
118+ '10D ' => '1452 ' ,
119+ '1T ' => 'BF1103 ' ,
120+ '4L ' => 'US ' ,
121+ ], $ barcode ->data );
122+ }
123+
124+ public function testParseOldMouserFormat (): void
125+ {
126+ $ barcode = EIGP114BarcodeScanResult::parseFormat06Code (">[)>06 \x1DP596-777A1-ND \x1D1PXAF4444 \x1DQ3 \x1D10D1452 \x1D1TBF1103 \x1D4LUS \x1E\x04" );
127+ $ this ->assertSame ([
128+ 'P ' => '596-777A1-ND ' ,
129+ '1P ' => 'XAF4444 ' ,
130+ 'Q ' => '3 ' ,
131+ '10D ' => '1452 ' ,
132+ '1T ' => 'BF1103 ' ,
133+ '4L ' => 'US ' ,
134+ ], $ barcode ->data );
135+ }
136+
104137 public function testParseFormat06Code (): void
105138 {
106139 $ barcode = EIGP114BarcodeScanResult::parseFormat06Code ("[)> \x1E06 \x1DP596-777A1-ND \x1D1PXAF4444 \x1DQ3 \x1D10D1452 \x1D1TBF1103 \x1D4LUS \x1E\x04" );
You can’t perform that action at this time.
0 commit comments