Skip to content

Commit b7dc50a

Browse files
committed
Fix toBytes regression
When using toBytes on strings containing multiple lines, the results are wrong. It used to work in pyscard 1.7.0 and before commit 1fd9457
1 parent 11502a1 commit b7dc50a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

smartcard/util/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def toBytes(bytestring):
9797
>>> toBytes("3B6500 009C1101 0103")
9898
[59, 101, 0, 0, 156, 17, 1, 1, 3]
9999
"""
100-
packedstring = bytestring.replace(' ', '').replace(' ','')
100+
packedstring = bytestring.replace(' ', '').replace(' ','').replace('\n', '')
101101
try:
102102
return list(map(lambda x: int(''.join(x), 16), zip(*[iter(packedstring)] * 2)))
103103
except KeyError:

test/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def test_toBytes(self):
2121
data_in = "3B6500 009C1101 0103"
2222
self.assertEqual(toBytes(data_in), data_out)
2323

24+
data_in = '''
25+
3B 65 00
26+
00 9C 11 01
27+
01 03
28+
'''
29+
self.assertEqual(toBytes(data_in), data_out)
2430

2531
def test_padd(self):
2632
data_in = toBytes("3B 65 00 00 9C 11 01 01 03")

0 commit comments

Comments
 (0)