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>
#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": {

Loading…
Cancel
Save