File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,8 @@ def __mul__(self, other):
268268
269269 for i , item in enumerate (self ):
270270 for j , other_item in enumerate (other ):
271+ if item == 0 or other_item == 0 :
272+ continue
271273 num [i + j ] ^= gexp (glog (item ) + glog (other_item ))
272274
273275 return Polynomial (num , 0 )
@@ -277,6 +279,12 @@ def __mod__(self, other):
277279 if difference < 0 :
278280 return self
279281
282+ if self [0 ] == 0 :
283+ num = list (self [1 :])
284+ if difference :
285+ num .append (0 )
286+ return Polynomial (num , 0 ) % other
287+
280288 ratio = glog (self [0 ]) - glog (other [0 ])
281289
282290 num = [
Original file line number Diff line number Diff line change @@ -23,6 +23,19 @@ def test_large():
2323 qr .make (fit = False )
2424
2525
26+ def test_glog_zero_data_with_leading_zeros ():
27+ """Regression test for issue #330: glog(0) ValueError with zero-heavy data."""
28+ qr = qrcode .QRCode (
29+ version = 6 ,
30+ error_correction = qrcode .constants .ERROR_CORRECT_L ,
31+ box_size = 10 ,
32+ border = 4 ,
33+ mask_pattern = 0 ,
34+ )
35+ qr .add_data ("http://test.com/abc" + "000" * 90 )
36+ qr .make ()
37+
38+
2639def test_invalid_version ():
2740 with pytest .raises (ValueError ):
2841 qrcode .QRCode (version = 42 )
You can’t perform that action at this time.
0 commit comments