Change Parse descriptor argument to string_view

Commit b3bf18f0ba changed the function
signature from Parse(const std::string& descriptor,...) to
Parse(std::span<const char> descriptor,...).

Calling this new version of Parse with a string literal will trigger
a confusing "Invalid characters in payload" due to the trailing "\0".

Switch to string_view and add a test.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
This commit is contained in:
Sjors Provoost
2025-11-20 13:44:30 +01:00
parent 1af46cff94
commit c0bfe72f6e
3 changed files with 15 additions and 5 deletions

View File

@@ -1262,4 +1262,13 @@ BOOST_AUTO_TEST_CASE(descriptor_test)
CheckUnparsable("tr(musig(tuus(oldepk(gg)ggggfgg)<,z(((((((((((((((((((((st)", "tr(musig(tuus(oldepk(gg)ggggfgg)<,z(((((((((((((((((((((st)","tr(): Too many ')' in musig() expression");
}
BOOST_AUTO_TEST_CASE(descriptor_literal_null_byte)
{
// Trailing '\0' string literal should be ignored.
FlatSigningProvider keys;
std::string err;
auto descs = Parse("pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)", keys, err, /*require_checksum=*/false);
BOOST_REQUIRE_MESSAGE(!descs.empty(), err);
}
BOOST_AUTO_TEST_SUITE_END()