Don't depend on locale when trimming strings.
Add TrimString(…) tests.
Add boost::algorithm::trim and boost::trim to list of locale dependent functions we want to avoid.
Don't depend on locale when trimming strings.
Add TrimString(…) tests.
Add boost::algorithm::trim and boost::trim to list of locale dependent functions we want to avoid.
766 | @@ -766,8 +767,6 @@ static std::string readStdin() 767 | if (ferror(stdin)) 768 | throw std::runtime_error("error reading stdin"); 769 | 770 | - boost::algorithm::trim_right(ret);
why does this not have a replacement?
It has: see L796 where it makes more sense :)
Even though it does make sense to trim all whitespace from a hex-encoded transaction, it still also makes sense to trim newline characters here (which should be locale-dependent).
@luke-jr I'm not sure I follow: could you explain why? Please include an example if possible where the new code would give bad results.
Wait, how are newline characters locale dependent?
What is the motivation for locale independent trimming?
What is the motivation for locale independent trimming?
See the developer notes:
"Avoid using locale dependent functions if possible. You can use the provided lint-locale-dependence.sh to check for accidental use of locale dependent functions.
Rationale: Unnecessary locale dependence can cause bugs that are very tricky to isolate and fix."
792 | @@ -794,7 +793,7 @@ static int CommandLineRawTx(int argc, char* argv[]) 793 | // param: hex-encoded bitcoin transaction 794 | std::string strHexTx(argv[1]); 795 | if (strHexTx == "-") // "-" implies standard input 796 | - strHexTx = readStdin(); 797 | + strHexTx = TrimString(readStdin());
This one actually should be locale-dependent.
@luke-jr I'm not sure I follow: could you explain why? Please include an example if possible where the new code would give bad results.
I'm not sure how important this specific is, but generally we do not use locale-dependent input handling in bitcoind nor utilities. We'd like to avoid differences in locale resulting in hard-to-reproduce bugs and unexpected behavior. Note that this tool is mainly for scripting use where deterministic behavior is important.
Developer notes are ultimately just notes, not a reason to do things the wrong way. Standard input from the user should be using locale-dependent functions.