Skip to content
Bitcoin Roots

v29.4-roots.3 · Commit 2: [PATCH 02/30] runtime: preserve shared operator controls

src/util/strencodings.cpp

Before: src/util/strencodings.cpp · After: src/util/strencodings.cpp

File metadata
index 15cb40aba1322395c49663222616cf63c723309a..db75599ba42be0b937b0b1dabf657c79b234ef4b 100644

Download original patch · Release notes

Diff rows 1–26 of 26. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

src/util/strencodings.cpp CHANGED
@@ -3,6 +3,7 @@
3
3
  // Distributed under the MIT software license, see the accompanying
4
4
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
 
6
+ #include <tinyformat.h>
6
7
  #include <util/strencodings.h>
7
8
 
8
9
  #include <crypto/hex_base.h>
@@ -25,14 +26,17 @@ static const std::string SAFE_CHARS[] =
25
26
  CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
26
27
  CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
27
28
  CHARS_ALPHA_NUM + "!*'();:@&=+$,/?#[]-_.~%", // SAFE_CHARS_URI
29
+ CHARS_ALPHA_NUM + " .,;-_/:?@()!\"#$%&'*+<=>[\\]^`{|}~" // SAFE_CHARS_PRINTABLE
28
30
  };
29
31
 
30
- std::string SanitizeString(std::string_view str, int rule)
32
+ std::string SanitizeString(std::string_view str, int rule, bool escape)
31
33
  {
32
34
  std::string result;
33
35
  for (char c : str) {
34
- if (SAFE_CHARS[rule].find(c) != std::string::npos) {
36
+ if (SAFE_CHARS[rule].find(c) != std::string::npos || (c == '%' && escape)) {
35
37
  result.push_back(c);
38
+ } else if (escape) {
39
+ result += strprintf("%%%02X", c);
36
40
  }
37
41
  }
38
42
  return result;