summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-10-05 13:57:24 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-10-05 13:57:24 +0200
commit1d238b70e2655e64b1cb1a51357a9eb0c753181d (patch)
tree225887e2662598a15ce2a98f1ca5ea0a146cd516 /src
parentd9615bbe41c830eb3941e3f6235d47b6a46e584d (diff)
Escape poll options (#128)
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp4
-rw-r--r--src/tools/StringTools.cpp18
2 files changed, 20 insertions, 2 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index ed1f07a..7ceb75e 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -903,7 +903,7 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, const std::string&> chat
args.emplace_back("question", question);
args.emplace_back("options", _tgTypeParser.parseArray<std::string>(
[](const std::string& option)->std::string {
- return "\"" + option + "\"";
+ return "\"" + StringTools::escapeJsonString(option) + "\"";
}, options));
if (!isAnonymous) {
args.emplace_back("is_anonymous", isAnonymous);
@@ -1760,7 +1760,7 @@ std::vector<Sticker::Ptr> Api::getCustomEmojiStickers(const std::vector<std::str
args.reserve(1);
args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray<std::string>([] (const std::string& customEmojiId) -> std::string {
- return "\"" + customEmojiId + "\"";
+ return "\"" + StringTools::escapeJsonString(customEmojiId) + "\"";
}, customEmojiIds));
return _tgTypeParser.parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args));
diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp
index 653047c..3e5e6c4 100644
--- a/src/tools/StringTools.cpp
+++ b/src/tools/StringTools.cpp
@@ -101,4 +101,22 @@ string urlDecode(const string& value) {
return result;
}
+std::string escapeJsonString(const std::string& value) {
+ string result;
+
+ for (const char& c : value) {
+ switch (c) {
+ case '"':
+ case '\\':
+ case '/':
+ result += '\\';
+ break;
+ }
+
+ result += c;
+ }
+
+ return result;
+}
+
}