aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2019-07-02 12:13:17 +0200
committerAndré Hartmann <aha_1980@gmx.de>2019-07-03 16:00:25 +0000
commit89dda94dca61e930b617800f54c16495e6abfa91 (patch)
tree779180dedccb0e91332c8d02c03d6468e3479f01
parent881f4d5f38b58788aacf03a31494b67b4dcfda35 (diff)
QtOutputFormatter: Support relative file:// links
QUrl does not have good support for relative file paths, and it seems there is little interest to change it: QTBUG-44921 Work around this by constructing the QUrl again on failure with fromLocalFile(). In this case, the "file://" scheme has to be omitted. This issue was detected because some compilers generate paths with native Windows separators, like "..\main.cpp" for the __FILE__ macro. Debugging the issue showed, that rather the relative path was the problem, as the QUrl constructor does not support it. Change-Id: I30074a3d11f9f43e05cd202f6d86c752ce184785 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/qtsupport/qtoutputformatter.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/plugins/qtsupport/qtoutputformatter.cpp b/src/plugins/qtsupport/qtoutputformatter.cpp
index 1bffe659cc..e6e6581928 100644
--- a/src/plugins/qtsupport/qtoutputformatter.cpp
+++ b/src/plugins/qtsupport/qtoutputformatter.cpp
@@ -239,7 +239,11 @@ void QtOutputFormatter::handleLink(const QString &href)
const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href);
if (qmlLineMatch.hasMatch()) {
- const QUrl fileUrl = QUrl(qmlLineMatch.captured(1));
+ const char scheme[] = "file://";
+ const QString filePath = qmlLineMatch.captured(1);
+ QUrl fileUrl = QUrl(filePath);
+ if (!fileUrl.isValid() && filePath.startsWith(scheme))
+ fileUrl = QUrl::fromLocalFile(filePath.mid(strlen(scheme)));
const int line = qmlLineMatch.captured(2).toInt();
openEditor(getFileToOpen(fileUrl), line);
return;
@@ -415,15 +419,27 @@ void QtSupportPlugin::testQtOutputFormatter_data()
<< " Loc: [../TestProject/test.cpp(123)]"
<< 9 << 37 << "../TestProject/test.cpp(123)"
<< "../TestProject/test.cpp" << 123 << -1;
+
+ QTest::newRow("Unix relative file link")
+ << "file://../main.cpp:157"
+ << 0 << 22 << "file://../main.cpp:157"
+ << "../main.cpp" << 157 << -1;
+
if (HostOsInfo::isWindowsHost()) {
QTest::newRow("Windows failed QTest link")
<< "..\\TestProject\\test.cpp(123) : failure location"
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
<< "../TestProject/test.cpp" << 123 << -1;
+
QTest::newRow("Windows failed QTest link with carriage return")
<< "..\\TestProject\\test.cpp(123) : failure location\r"
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
<< "../TestProject/test.cpp" << 123 << -1;
+
+ QTest::newRow("Windows relative file link with native separator")
+ << "file://..\\main.cpp:157"
+ << 0 << 22 << "file://..\\main.cpp:157"
+ << "../main.cpp" << 157 << -1;
}
}