ClangCodeModel: Do not call FilePath::exists() on random strings

Fixes: QTCREATORBUG-29356
Change-Id: I6f4d89a6823829a7ecf16200786621321fea61a5
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2023-07-03 13:03:21 +02:00
parent 7977d3ac37
commit 20cb9b6e69
3 changed files with 23 additions and 1 deletions

View File

@@ -1114,7 +1114,23 @@ void ClangdClient::gatherHelpItemForTooltip(const HoverRequest::Response &hoverR
cleanString.remove('`');
const QStringList lines = cleanString.trimmed().split('\n');
for (const QString &line : lines) {
const auto markupFilePath = Utils::FilePath::fromUserInput(line.simplified());
const QString possibleFilePath = line.simplified();
const auto looksLikeFilePath = [&] {
if (possibleFilePath.length() < 3)
return false;
if (osType() == OsTypeWindows) {
if (possibleFilePath.startsWith(R"(\\)"))
return true;
return possibleFilePath.front().isLetter()
&& possibleFilePath.at(1) == ':'
&& possibleFilePath.at(2) == '\\';
}
return possibleFilePath.front() == '/'
&& possibleFilePath.at(1).isLetterOrNumber();
};
if (!looksLikeFilePath())
continue;
const auto markupFilePath = Utils::FilePath::fromUserInput(possibleFilePath);
if (markupFilePath.exists()) {
d->setHelpItemForTooltip(hoverResponse.id(),
filePath,