diff --git a/electrum/transaction.py b/electrum/transaction.py index 7f621af4d..5bbbdf8ea 100644 --- a/electrum/transaction.py +++ b/electrum/transaction.py @@ -36,6 +36,7 @@ from enum import IntEnum import itertools import binascii import copy +import re import electrum_ecc as ecc from electrum_ecc.util import bip340_tagged_hash @@ -1482,7 +1483,11 @@ def convert_raw_tx_to_hex(raw: Union[str, bytes]) -> str: if not raw: raise ValueError("empty string") raw_unstripped = raw - raw = raw.strip() + # remove all whitespace characters + if isinstance(raw, str): + raw = re.sub(r'\s', '', raw) + else: + raw = re.sub(rb'\s', b'', raw) # try hex try: return binascii.unhexlify(raw).hex() diff --git a/tests/test_transaction.py b/tests/test_transaction.py index 9b0402a19..ed74461e8 100644 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -276,10 +276,11 @@ class TestTransaction(ElectrumTestCase): data = raw_tx.data tx_from_any(data) # test if raises (should not) else: + mid = len(raw_tx.data) // 2 if isinstance(raw_tx.data, str): - data = whitespace_str + raw_tx.data + whitespace_str + data = whitespace_str + raw_tx.data[:mid] + whitespace_str + raw_tx.data[mid:] + whitespace_str else: - data = whitespace_bytes + raw_tx.data + whitespace_bytes + data = whitespace_bytes + raw_tx.data[:mid] + whitespace_bytes + raw_tx.data[mid:] + whitespace_bytes if raw_tx.is_whitespace_allowed: tx_from_any(data) # test if raises (should not) else: