aboutsummaryrefslogtreecommitdiff
path: root/src/utilstrencodings.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2015-09-09 14:24:56 +0200
committerMarcoFalke <falke.marco@gmail.com>2015-09-16 15:23:29 +0200
commit1c1b1b315f2f89584abe9a7558945dea2fbee708 (patch)
tree80c5e16ed073213d4645f88eb42c398ed194c27f /src/utilstrencodings.cpp
parent536207f3167daad1fa3d60a1de7d9cb55db28ac9 (diff)
downloadbitcoin-1c1b1b315f2f89584abe9a7558945dea2fbee708.tar.xz
[uacomment] Sanitize per BIP-0014
* SanitizeString() can be requested to be more strict * Throw error when SanitizeString() changes uacomments * Fix tests
Diffstat (limited to 'src/utilstrencodings.cpp')
-rw-r--r--src/utilstrencodings.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp
index 1f7a2cae2c..76c22f7353 100644
--- a/src/utilstrencodings.cpp
+++ b/src/utilstrencodings.cpp
@@ -14,17 +14,20 @@
using namespace std;
-string SanitizeString(const string& str)
+static const string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+static const string SAFE_CHARS[] =
+{
+ CHARS_ALPHA_NUM + " .,;_/:?@()", // SAFE_CHARS_DEFAULT
+ CHARS_ALPHA_NUM + " .,;_?@" // SAFE_CHARS_UA_COMMENT
+};
+
+string SanitizeString(const string& str, int rule)
{
- /**
- * safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
- * even possibly remotely dangerous like & or >
- */
- static string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@()");
string strResult;
for (std::string::size_type i = 0; i < str.size(); i++)
{
- if (safeChars.find(str[i]) != std::string::npos)
+ if (SAFE_CHARS[rule].find(str[i]) != std::string::npos)
strResult.push_back(str[i]);
}
return strResult;