Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion electrum/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,11 @@ def _get_func_expr(s: str) -> Tuple[str, str]:
try:
start = s.index("(")
end = s.rindex(")")
return s[0:start], s[start + 1:end]
except ValueError:
raise ValueError("A matching pair of parentheses cannot be found")
if end != len(s) - 1:
raise ValueError("Trailing characters '{}' after closing parenthesis".format(s[end + 1:]))
return s[0:start], s[start + 1:end]


def _get_const(s: str, const: str) -> str:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ def test_parse_descriptor_with_key_at_end_without_origin(self):
def test_parse_empty_descriptor(self):
self.assertRaises(ValueError, parse_descriptor, "")

@as_testnet
def test_parse_descriptor_rejects_trailing_characters(self):
key = "tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B"
# trailing characters after the closing parenthesis must not be silently ignored
self.assertRaises(ValueError, parse_descriptor, "wpkh({}/0/0)abc".format(key))
# the same applies to the closing parenthesis of a nested descriptor
self.assertRaises(ValueError, parse_descriptor, "sh(wpkh({}/0/0))x".format(key))

@as_testnet
def test_parse_descriptor_replace_h(self):
d = "wpkh([00000001/84'/1'/0']tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/0/0)"
Expand Down