From 26bc95345fdee4118c611f1d4e13c5bc62f3c0a8 Mon Sep 17 00:00:00 2001 From: CryptoVote Date: Fri, 4 Mar 2016 00:25:59 -0600 Subject: [PATCH] Removes forward slashes (/) from user agent in Peers tab UI. user agent is prefixed and suffixed with forward slashes occupying two spaces and seem unnecessary for the Qt wallet UI. --- src/main.cpp | 2 +- src/utilstrencodings.cpp | 11 +++++++++++ src/utilstrencodings.h | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a55fd367aa6e..3588f3fa6aa3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4343,7 +4343,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vRecv >> addrFrom >> nNonce; if (!vRecv.empty()) { vRecv >> LIMITED_STRING(pfrom->strSubVer, 256); - pfrom->cleanSubVer = SanitizeString(pfrom->strSubVer); + pfrom->cleanSubVer = SanitizeSubVersionString(pfrom->strSubVer); } if (!vRecv.empty()) vRecv >> pfrom->nStartingHeight; diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 9e2e21fb0132..a253c7821d59 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -36,6 +36,17 @@ string SanitizeString(const string& str) return strResult; } +/// Formats the network peer user agent text (or clean subversion) +/// by removing the begining and ending charactors(/). +/// example: /Dash Core:0.12.0.56/ --> Dash Core:0.12.0.56 +string SanitizeSubVersionString(const string& str) +{ + string strResult = SanitizeString(str); + if ((strResult.length() > 3) && (strResult.substr(0,1) == "/") && (strResult.substr((strResult.length()-1),1) == "/")) + strResult = strResult.substr(1, (strResult.length() - 2)); + return strResult; +} + const signed char p_util_hexdigit[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h index 358fb4f55f09..66e7441c52a9 100644 --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -24,6 +24,7 @@ #define PAIRTYPE(t1, t2) std::pair std::string SanitizeString(const std::string& str); +std::string SanitizeSubVersionString(const std::string& str); std::vector ParseHex(const char* psz); std::vector ParseHex(const std::string& str); signed char HexDigit(char c);