Summary
This PR trims wallet names using util::TrimStringView before the empty check, across all call sites that currently guard against empty wallet names
Motivation: Although there is a check against empty wallet names, it does not reject wallet names consisting solely of whitespace. As a result, the RPC command below succeeds and creates a wallet with a whitespace-only name. Such names are not meaningful and are effectively indistinguishable from nameless directories to users, so they should be rejected in the same way as empty wallet names.
bitcoin-cli createwallet " "
util::TrimStringView; has been preferred as opposed to util::TrimString; to prevent mutating the user input but guarding against space-only names. This means that the wallet name can have leading and trailing white space unless requested otherwise.
Testing
Before:
ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ./bitcoin-cli createwallet " "
{
"name": " "
}
ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ls ~/.bitcoin/regtest/wallets/
' ' ' ' ' '
ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$
After:
ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli createwallet " "
error code: -8
error message:
Wallet name cannot be empty
ratedg@0xratedg:~/Desktop/bitcoin/build/bin$