QUrl::fromUserInput(with cwd) fix handling of files with trailing spaces
The call to trimmed() makes sense for URLs typed in a browser's location bar, but its use in every code path made it impossible to open a file with a trailing space in command-line tools that uses fromUserInput(cwd) to handle command-line arguments, as recommended. For instance kde-open5 "file.txt " would fail. Change-Id: Ie61182684521d91f077d3e76f95b7240965ab405 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8cb9314971
commit
9ffc9e306f
@ -4170,10 +4170,10 @@ QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirecto
|
||||
return url;
|
||||
}
|
||||
|
||||
QUrl url = QUrl(trimmedString, QUrl::TolerantMode);
|
||||
QUrl url = QUrl(userInput, QUrl::TolerantMode);
|
||||
// Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes)
|
||||
if (url.isRelative() && !QDir::isAbsolutePath(trimmedString)) {
|
||||
QFileInfo fileInfo(QDir(workingDirectory), trimmedString);
|
||||
if (url.isRelative() && !QDir::isAbsolutePath(userInput)) {
|
||||
QFileInfo fileInfo(QDir(workingDirectory), userInput);
|
||||
if ((options & AssumeLocalFile) || fileInfo.exists())
|
||||
return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
|
||||
}
|
||||
|
@ -3088,7 +3088,7 @@ void tst_QUrl::fromUserInputWithCwd_data()
|
||||
}
|
||||
|
||||
// Existing files
|
||||
for (const char *fileName : {"file.txt", "file#a.txt", "file .txt"}) {
|
||||
for (const char *fileName : {"file.txt", "file#a.txt", "file .txt", "file.txt "}) {
|
||||
const QString filePath = base + '/' + fileName;
|
||||
QFile file(filePath);
|
||||
QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath));
|
||||
|
Loading…
Reference in New Issue
Block a user