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