Skip to content

Commit

Permalink
Don't use ZXing's --raw option except with v3.5.3+
Browse files Browse the repository at this point in the history
(This probably should have been done as part of 0512c7a.)

The --raw option was added in 3.5.0, but broken for certain barcode types
(PDF_417 and maybe others) until 3.5.3: CommandLineRunner will fail with
NullPointerException.

See zxing/zxing#1682 and
zxing/zxing#1683 for more details.
  • Loading branch information
dlenski committed Nov 2, 2023
1 parent 12307eb commit 07d94c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_version():
@with_setup(setup_reader)
def _check_decoding(filename, expected_format, expected_raw, extra={}, as_Image=False):
global test_reader
if test_reader.zxing_version_info >= (3, 5, 0) and expected_format == 'PDF_417':
if (3, 5, 0) <= test_reader.zxing_version_info < (3, 5, 3) and expected_format == 'PDF_417':
# See https://github.com/zxing/zxing/issues/1682 and https://github.com/zxing/zxing/issues/1683
raise unittest.SkipTest("ZXing v{} CommandLineRunner is broken for combination of {} barcode format and --raw option".format(
test_reader.zxing_version, expected_format))
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_possible_formats():
def test_decoding_multiple():
global test_reader
# See https://github.com/zxing/zxing/issues/1682 and https://github.com/zxing/zxing/issues/1683
_tvi = [x for x in test_valid_images if test_reader.zxing_version_info < (3, 5, 0) or x[1] != 'PDF_417']
_tvi = [x for x in test_valid_images if not ((3, 5, 0) <= test_reader.zxing_version_info < (3, 5, 3) and x[1] == 'PDF_417')]
filenames = [os.path.join(test_barcode_dir, filename) for filename, expected_format, expected_raw in _tvi]
for dec, (filename, expected_format, expected_raw) in zip(test_reader.decode(filenames, pure_barcode=True), _tvi):
assert dec.raw == expected_raw, (
Expand Down
4 changes: 3 additions & 1 deletion zxing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
file_uris.append(pathlib.Path(fn).absolute().as_uri())

cmd = [self.java, '-cp', self.classpath, self.cls] + file_uris
if self.zxing_version_info and self.zxing_version_info >= (3, 5, 0):
if self.zxing_version_info and self.zxing_version_info >= (3, 5, 3):
# The --raw option was added in 3.5.0, but broken for certain barcode types (PDF_417 and maybe others) until 3.5.3
# See https://github.com/zxing/zxing/issues/1682 and https://github.com/zxing/zxing/issues/1683
cmd.append('--raw')
if try_harder:
cmd.append('--try_harder')
Expand Down

0 comments on commit 07d94c5

Please sign in to comment.