Skip to content

Commit f7eef38

Browse files
authored
Merge pull request #522 from mcserep/fix-syntax-highlight
Fix server-side syntax highlighting
2 parents 1485133 + d6ebc56 commit f7eef38

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

plugins/cpp/service/src/cppservice.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,9 @@ void CppServiceHandler::getSyntaxHighlight(
12261226
continue;
12271227

12281228
// Regular expression to find element position
1229-
std::string reg = "\\b" + node.astValue + "\\b";
1229+
const std::regex specialChars { R"([-[\]{}()*+?.,\^$|#\s])" };
1230+
std::string sanitizedAstValue = std::regex_replace(node.astValue, specialChars, R"(\$&)");
1231+
std::string reg = "\\b" + sanitizedAstValue + "\\b";
12301232

12311233
for (std::size_t i = node.location.range.start.line - 1;
12321234
i < node.location.range.end.line && i < content.size();

0 commit comments

Comments
 (0)