forked from qt-creator/qt-creator
Terminal: Fix Cwd escaping
The shellintegration script escape the current working dir. We were missing the code to unescape the paths. This was particularly visible on Windows powershell where backslash was escaped by "\x5c". Change-Id: If697722986c72ebbc19d5ec8e3930321f3af7b6a Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -84,6 +84,30 @@ bool ShellIntegration::canIntegrate(const Utils::CommandLine &cmdLine)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString unescape(QStringView str)
|
||||||
|
{
|
||||||
|
QString result;
|
||||||
|
result.reserve(str.length());
|
||||||
|
for (int i = 0; i < str.length(); ++i) {
|
||||||
|
if (str[i] == '\\' && str.length() > i + 1) {
|
||||||
|
if (str[i + 1] == '\\') {
|
||||||
|
// e.g. \\ -> "\"
|
||||||
|
result.append('\\');
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
} else if (str[i + 1] == 'x' && str.length() > i + 3) {
|
||||||
|
// e.g.: \x5c -> \ (0x5c is the ASCII code for \)
|
||||||
|
result.append(QChar(str.sliced(i + 2, 2).toUShort(nullptr, 16)));
|
||||||
|
i += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append(str[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ShellIntegration::onOsc(int cmd, std::string_view str, bool initial, bool final)
|
void ShellIntegration::onOsc(int cmd, std::string_view str, bool initial, bool final)
|
||||||
{
|
{
|
||||||
if (initial)
|
if (initial)
|
||||||
@@ -116,7 +140,7 @@ void ShellIntegration::onOsc(int cmd, std::string_view str, bool initial, bool f
|
|||||||
} else if (command[0] == 'P') {
|
} else if (command[0] == 'P') {
|
||||||
const auto [key, value] = Utils::splitAtFirst(data, '=');
|
const auto [key, value] = Utils::splitAtFirst(data, '=');
|
||||||
if (key == QStringView(u"Cwd"))
|
if (key == QStringView(u"Cwd"))
|
||||||
emit currentDirChanged(value.toString());
|
emit currentDirChanged(unescape(value.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user