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('`'); cleanString.remove('`');
const QStringList lines = cleanString.trimmed().split('\n'); const QStringList lines = cleanString.trimmed().split('\n');
for (const QString &line : lines) { 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()) { if (markupFilePath.exists()) {
d->setHelpItemForTooltip(hoverResponse.id(), d->setHelpItemForTooltip(hoverResponse.id(),
filePath, filePath,

View File

@@ -2169,6 +2169,11 @@ DocumentUri Client::hostPathToServerUri(const Utils::FilePath &path) const
}); });
} }
OsType Client::osType() const
{
return d->m_serverDeviceTemplate.osType();
}
void Client::registerCustomMethod(const QString &method, const CustomMethodHandler &handler) void Client::registerCustomMethod(const QString &method, const CustomMethodHandler &handler)
{ {
d->m_customHandlers.insert(method, handler); d->m_customHandlers.insert(method, handler);

View File

@@ -168,6 +168,7 @@ public:
LanguageServerProtocol::DocumentUri::PathMapper hostPathMapper() const; LanguageServerProtocol::DocumentUri::PathMapper hostPathMapper() const;
Utils::FilePath serverUriToHostPath(const LanguageServerProtocol::DocumentUri &uri) const; Utils::FilePath serverUriToHostPath(const LanguageServerProtocol::DocumentUri &uri) const;
LanguageServerProtocol::DocumentUri hostPathToServerUri(const Utils::FilePath &path) const; LanguageServerProtocol::DocumentUri hostPathToServerUri(const Utils::FilePath &path) const;
Utils::OsType osType() const;
// custom methods // custom methods
using CustomMethodHandler = std::function<void( using CustomMethodHandler = std::function<void(