File tree 2 files changed +12
-7
lines changed
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ def decode(
294
294
logger_warning (
295
295
"missing EOD in ASCIIHexDecode, check if output is OK" , __name__
296
296
)
297
- break # Reached end of string even if no EOD
297
+ break # Reached end of string without an EOD
298
298
char = data [index : index + 1 ]
299
299
if char == b">" :
300
300
break
@@ -306,7 +306,13 @@ def decode(
306
306
retval += bytes ((int (hex_pair , base = 16 ),))
307
307
hex_pair = b""
308
308
index += 1
309
- assert hex_pair == b""
309
+ # If the filter encounters the EOD marker after reading
310
+ # an odd number of hexadecimal digits,
311
+ # it shall behave as if a 0 (zero) followed the last digit.
312
+ # For every even number of hexadecimal digits, hex_pair is reset to b"".
313
+ if hex_pair != b"" :
314
+ hex_pair += b"0"
315
+ retval += bytes ((int (hex_pair , base = 16 ),))
310
316
return retval
311
317
312
318
@@ -351,7 +357,7 @@ def decode(
351
357
logger_warning (
352
358
"missing EOD in RunLengthDecode, check if output is OK" , __name__
353
359
)
354
- break # reach End Of String even if no EOD
360
+ break # Reached end of string without an EOD
355
361
length = data [index ]
356
362
index += 1
357
363
if length == 128 :
Original file line number Diff line number Diff line change @@ -104,6 +104,8 @@ def test_flate_decode_decompress_with_array_params(params):
104
104
), # Same as previous, but whitespaced
105
105
("30313233343536373839616263646566414243444546>" , string .hexdigits .encode ()),
106
106
("20090a0d0b0c>" , string .whitespace .encode ()),
107
+ # Odd number of hexadecimal digits behaves as if a 0 (zero) followed the last digit
108
+ ("3938373635343332313>" , string .digits [::- 1 ].encode ()),
107
109
],
108
110
ids = [
109
111
"empty" ,
@@ -114,16 +116,13 @@ def test_flate_decode_decompress_with_array_params(params):
114
116
"digits_whitespace" ,
115
117
"hexdigits" ,
116
118
"whitespace" ,
119
+ "odd_number" ,
117
120
],
118
121
)
119
122
def test_ascii_hex_decode_method (data , expected ):
120
123
"""
121
124
Feeds a bunch of values to ASCIIHexDecode.decode() and ensures the
122
125
correct output is returned.
123
-
124
- TODO What is decode() supposed to do for such inputs as ">>", ">>>" or
125
- any other not terminated by ">"? (For the latter case, an exception
126
- is currently raised.)
127
126
"""
128
127
assert ASCIIHexDecode .decode (data ) == expected
129
128
You can’t perform that action at this time.
0 commit comments