summaryrefslogtreecommitdiff
path: root/src/utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.hpp')
-rw-r--r--src/utils.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils.hpp b/src/utils.hpp
index f0d71d6..ebbdaf6 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -46,13 +46,39 @@ class Credentials
return passBuf;
}
+ void escapeCommas()
+ {
+ if (!commasEscaped)
+ {
+ escapeComma(userBuf);
+ escapeComma(passBuf);
+ commasEscaped = true;
+ }
+ }
+
private:
Credentials() = delete;
Credentials(const Credentials&) = delete;
Credentials& operator=(const Credentials&) = delete;
+ /* escape ',' (coma) by ',,' */
+ void escapeComma(std::string& s)
+ {
+ std::string temp;
+ std::for_each(s.begin(), s.end(), [&temp](const auto& c) {
+ *std::back_inserter(temp) = c;
+ if (c == ',')
+ {
+ *std::back_inserter(temp) = c;
+ }
+ });
+ std::swap(s, temp);
+ secureCleanup(temp);
+ }
+
std::string userBuf;
std::string passBuf;
+ bool commasEscaped{false};
};
class CredentialsProvider
@@ -83,6 +109,11 @@ class CredentialsProvider
{
}
+ void escapeCommas()
+ {
+ credentials.escapeCommas();
+ }
+
const std::string& user()
{
return credentials.user();