forked from qt-creator/qt-creator
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:
@@ -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,
|
||||
|
@@ -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)
|
||||
{
|
||||
d->m_customHandlers.insert(method, handler);
|
||||
|
@@ -168,6 +168,7 @@ public:
|
||||
LanguageServerProtocol::DocumentUri::PathMapper hostPathMapper() const;
|
||||
Utils::FilePath serverUriToHostPath(const LanguageServerProtocol::DocumentUri &uri) const;
|
||||
LanguageServerProtocol::DocumentUri hostPathToServerUri(const Utils::FilePath &path) const;
|
||||
Utils::OsType osType() const;
|
||||
|
||||
// custom methods
|
||||
using CustomMethodHandler = std::function<void(
|
||||
|
Reference in New Issue
Block a user