Browse Source

Added file path escaping to language_protocol_server_test.cpp

pipelines/353213535
eidheim 5 years ago
parent
commit
30ce9ca3a4
  1. 29
      tests/language_protocol_server_test.cpp

29
tests/language_protocol_server_test.cpp

@ -7,6 +7,31 @@
#include <io.h> #include <io.h>
#endif #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() { int main() {
#ifdef _WIN32 #ifdef _WIN32
@ -447,7 +472,7 @@ int main() {
"id": "5", "id": "5",
"result": [ "result": [
{ {
"uri": "file://)" + file_path.string() + "uri": "file://)" + escape_text(file_path.string()) +
R"(", R"(",
"range": { "range": {
"start": { "start": {
@ -461,7 +486,7 @@ int main() {
} }
}, },
{ {
"uri": "file://)" + file_path.string() + "uri": "file://)" + escape_text(file_path.string()) +
R"(", R"(",
"range": { "range": {
"start": { "start": {

Loading…
Cancel
Save