mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
36694d3852
This is done by HTTP POSTing to a location specified by `sv_modhelp_url`. We also provide a `src/modhelp/server.py` which can use theses POSTs to forward them to Discord servers. The POST contains a JSON object payload, with the keys `"port"` which contains the server port, `"player_id"` which contains the calling player's client ID, `"player_name"` which contains the calling player's nick and `"message"` which is the user-specified message. Make JSON-escaping function public, add tests and fix bugs uncovered by these tests. Supersedes #1129.
23 lines
800 B
C++
23 lines
800 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <engine/shared/fetcher.h>
|
|
|
|
TEST(Json, Escape)
|
|
{
|
|
char aBuf[128];
|
|
char aSmall[2];
|
|
char aSix[6];
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), ""), "");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "a"), "a");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\n"), "\\n");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\\"), "\\\\"); // https://www.xkcd.com/1638/
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "\x1b"), "\\u001b"); // escape
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "愛"), "愛");
|
|
EXPECT_STREQ(EscapeJson(aBuf, sizeof(aBuf), "😂"), "😂");
|
|
|
|
// Truncations
|
|
EXPECT_STREQ(EscapeJson(aSmall, sizeof(aSmall), "\\"), "");
|
|
EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "\x01"), "");
|
|
EXPECT_STREQ(EscapeJson(aSix, sizeof(aSix), "aaaaaa"), "aaaaa");
|
|
}
|