ClangCodeModel: Fix check for strings that look like file paths

Backslashes in the markup string are escaped with another backslash, so
we need to check for two consecutive ones on Windows.
Otherwise, qdoc/doxygen commands such as "\note" are interpreted as files
and trigger expensive I/O operations.

Fixes: QTCREATORBUG-29975
Change-Id: I822f57a8612274ff4112063928cab21b9d7ca792
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2023-11-27 12:48:08 +01:00
parent a71b33944b
commit 6ed456ed9e

View File

@@ -1139,14 +1139,15 @@ void ClangdClient::gatherHelpItemForTooltip(const HoverRequest::Response &hoverR
for (const QString &line : lines) {
const QString possibleFilePath = line.simplified();
const auto looksLikeFilePath = [&] {
if (possibleFilePath.length() < 3)
if (possibleFilePath.length() < 4)
return false;
if (osType() == OsTypeWindows) {
if (possibleFilePath.startsWith(R"(\\)"))
if (possibleFilePath.startsWith(R"(\\\\)"))
return true;
return possibleFilePath.front().isLetter()
&& possibleFilePath.at(1) == ':'
&& possibleFilePath.at(2) == '\\';
&& possibleFilePath.at(2) == '\\'
&& possibleFilePath.at(3) == '\\';
}
return possibleFilePath.front() == '/'
&& possibleFilePath.at(1).isLetterOrNumber();