From 30ce9ca3a4aef8e3df15f516506632b30b82e0f7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 20 Jun 2021 13:35:45 +0200 Subject: [PATCH] Added file path escaping to language_protocol_server_test.cpp --- tests/language_protocol_server_test.cpp | 29 +++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/language_protocol_server_test.cpp b/tests/language_protocol_server_test.cpp index 7a73795..b3535d2 100644 --- a/tests/language_protocol_server_test.cpp +++ b/tests/language_protocol_server_test.cpp @@ -7,6 +7,31 @@ #include #endif +std::string escape_text(std::string text) { + for(size_t c = 0; c < text.size(); ++c) { + if(text[c] == '\n') { + text.replace(c, 1, "\\n"); + ++c; + } + else if(text[c] == '\r') { + text.replace(c, 1, "\\r"); + ++c; + } + else if(text[c] == '\t') { + text.replace(c, 1, "\\t"); + ++c; + } + else if(text[c] == '"') { + text.replace(c, 1, "\\\""); + ++c; + } + else if(text[c] == '\\') { + text.replace(c, 1, "\\\\"); + ++c; + } + } + return text; +} int main() { #ifdef _WIN32 @@ -447,7 +472,7 @@ int main() { "id": "5", "result": [ { - "uri": "file://)" + file_path.string() + + "uri": "file://)" + escape_text(file_path.string()) + R"(", "range": { "start": { @@ -461,7 +486,7 @@ int main() { } }, { - "uri": "file://)" + file_path.string() + + "uri": "file://)" + escape_text(file_path.string()) + R"(", "range": { "start": {