mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdecore: never output file:// for local files
there is a fix for that legacy thing Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
cb8a624390
commit
40da298881
4 changed files with 41 additions and 46 deletions
|
@ -33,7 +33,6 @@
|
|||
#include <QHostInfo>
|
||||
|
||||
static const char s_kdeUriListMime[] = "application/x-kde4-urilist";
|
||||
static const char s_kurlLocalFileDelimiter = 'l';
|
||||
|
||||
// FIXME: using local files to pass around queries and fragments is totally bonkers, this will make
|
||||
// sure they are not a thing
|
||||
|
@ -43,7 +42,7 @@ static const int kurlDebugArea = 181; // see kdebug.areas
|
|||
|
||||
void kCheckLocalFile(const KUrl *kurl)
|
||||
{
|
||||
if (kurl->isLocalFile() && kurl->queryPairDelimiter() == s_kurlLocalFileDelimiter) {
|
||||
if (kurl->isLocalFile()) {
|
||||
if (kurl->hasQuery() || kurl->hasFragment()) {
|
||||
kFatal(kurlDebugArea) << "Query or fragment detected in" << kurl->prettyUrl();
|
||||
}
|
||||
|
@ -355,7 +354,6 @@ KUrl::KUrl(const QString &str)
|
|||
if (!str.isEmpty()) {
|
||||
if (str[0] == QLatin1Char('/') || str[0] == QLatin1Char('~')) {
|
||||
setPath(str);
|
||||
setQueryDelimiters('=', s_kurlLocalFileDelimiter);
|
||||
} else {
|
||||
setUrl(str, QUrl::TolerantMode);
|
||||
}
|
||||
|
@ -368,7 +366,6 @@ KUrl::KUrl(const char *str)
|
|||
if (str && str[0]) {
|
||||
if (str[0] == '/' || str[0] == '~') {
|
||||
setPath(QString::fromUtf8(str));
|
||||
setQueryDelimiters('=', s_kurlLocalFileDelimiter);
|
||||
} else {
|
||||
setUrl(QUrl::fromPercentEncoding(str), QUrl::TolerantMode);
|
||||
}
|
||||
|
@ -381,7 +378,6 @@ KUrl::KUrl(const QByteArray &str)
|
|||
if (!str.isEmpty()) {
|
||||
if (str[0] == '/' || str[0] == '~') {
|
||||
setPath(QString::fromUtf8(str.constData(), str.size()));
|
||||
setQueryDelimiters('=', s_kurlLocalFileDelimiter);
|
||||
} else {
|
||||
setUrl(QUrl::fromPercentEncoding(str), QUrl::TolerantMode);
|
||||
}
|
||||
|
@ -445,7 +441,7 @@ bool KUrl::equals(const KUrl &u, const EqualsOptions &options) const
|
|||
return false;
|
||||
}
|
||||
|
||||
return (scheme() == u.scheme() &&
|
||||
return ((scheme() == u.scheme() || isLocalFile() && u.isLocalFile()) &&
|
||||
authority() == u.authority() && // user+pass+host+port
|
||||
query() == u.query() && fragment() == u.fragment());
|
||||
}
|
||||
|
@ -540,7 +536,7 @@ QString KUrl::url(AdjustPathOption trailing) const
|
|||
}
|
||||
const bool islocalfile = isLocalFile();
|
||||
const QString urlpath = path(trailing);
|
||||
if (islocalfile && queryPairDelimiter() == s_kurlLocalFileDelimiter) {
|
||||
if (islocalfile) {
|
||||
#ifdef KURL_COMPAT_CHECK
|
||||
kCheckLocalFile(this);
|
||||
#endif
|
||||
|
@ -555,9 +551,6 @@ QString KUrl::url(AdjustPathOption trailing) const
|
|||
}
|
||||
return result;
|
||||
}
|
||||
if (islocalfile && (urlpath.isEmpty() || urlpath == QLatin1String("/"))) {
|
||||
return QString::fromLatin1("file:///");
|
||||
}
|
||||
if (trailing == AddTrailingSlash) {
|
||||
return QUrl::toString(QUrl::AddTrailingSlash);
|
||||
} else if (trailing == RemoveTrailingSlash) {
|
||||
|
@ -788,14 +781,22 @@ QString KUrl::relativeUrl(const KUrl &base_url, const KUrl &url)
|
|||
|
||||
void KUrl::setPath(const QString &_path)
|
||||
{
|
||||
QString path = KShell::tildeExpand(_path);
|
||||
if (path.isEmpty()) {
|
||||
path = _path;
|
||||
QString newPath = KShell::tildeExpand(_path);
|
||||
if (newPath.isEmpty()) {
|
||||
newPath = _path;
|
||||
}
|
||||
if (scheme().isEmpty() && !path.startsWith(QLatin1String("file:/"))) {
|
||||
if (newPath.startsWith(QLatin1String("file://"))) {
|
||||
newPath.chop(7);
|
||||
}
|
||||
if (scheme().isEmpty()) {
|
||||
if (newPath.isEmpty()) {
|
||||
// Empty scheme and path - that's null/empty local file URL regardless of query and fragment
|
||||
QUrl::clear();
|
||||
return;
|
||||
}
|
||||
setScheme(QLatin1String("file"));
|
||||
}
|
||||
QUrl::setPath(path);
|
||||
QUrl::setPath(newPath);
|
||||
}
|
||||
|
||||
void KUrl::populateMimeData(QMimeData *mimeData, const MetaDataMap &metaData, MimeDataFlags flags) const
|
||||
|
|
|
@ -57,7 +57,7 @@ void KUrlMimeTest::testURLList()
|
|||
const QList<QUrl> qurls = mimeData->urls();
|
||||
QCOMPARE(qurls.count(), urls.count());
|
||||
for (int i = 0; i < qurls.count(); ++i )
|
||||
QCOMPARE(qurls[i], static_cast<QUrl>(decodedURLs[i]));
|
||||
QCOMPARE(qurls[i].toString(), decodedURLs[i].url());
|
||||
|
||||
QVERIFY( !decodedMetaData.isEmpty() );
|
||||
QCOMPARE( decodedMetaData["key"], QString( "value" ) );
|
||||
|
@ -133,6 +133,6 @@ void KUrlMimeTest::testMostLocalUrlList()
|
|||
const QList<QUrl> qurls = mimeData->urls();
|
||||
QCOMPARE(qurls.count(), localUrls.count());
|
||||
for (int i = 0; i < qurls.count(); ++i )
|
||||
QCOMPARE(qurls[i], static_cast<QUrl>(localUrls[i]));
|
||||
QCOMPARE(qurls[i].toString(), localUrls[i].url());
|
||||
delete mimeData;
|
||||
}
|
||||
|
|
|
@ -59,14 +59,8 @@ void KUrlTest::testHash()
|
|||
testurl.setQuery(url.query());
|
||||
testurl.setFragment(url.fragment());
|
||||
// qDebug() << Q_FUNC_INFO << url << testurl;
|
||||
if (testurl.path().isEmpty() || testurl.url().contains(QLatin1String("kde//"))) {
|
||||
QEXPECT_FAIL("", "The legacy of KUrl::setPath()", Continue);
|
||||
}
|
||||
QCOMPARE(url.url(), testurl.url());
|
||||
// qDebug() << qHash(url) << qHash(testurl);
|
||||
if (testurl.path().isEmpty() || testurl.url().contains(QLatin1String("kde//"))) {
|
||||
QEXPECT_FAIL("", "The legacy of KUrl::setPath()", Continue);
|
||||
}
|
||||
QCOMPARE(qHash(url), qHash(testurl));
|
||||
}
|
||||
|
||||
|
@ -228,19 +222,19 @@ void KUrlTest::testUrl_data()
|
|||
|
||||
QTest::newRow("local file 1")
|
||||
<< KUrl("file:///")
|
||||
<< QString::fromLatin1("file:///")
|
||||
<< QString::fromLatin1("file:///")
|
||||
<< QString::fromLatin1("file:///");
|
||||
<< QString::fromLatin1("/")
|
||||
<< QString::fromLatin1("/")
|
||||
<< QString::fromLatin1("/");
|
||||
QTest::newRow("local file 2")
|
||||
<< KUrl("file:///home/kde/")
|
||||
<< QString::fromLatin1("file:///home/kde/")
|
||||
<< QString::fromLatin1("file:///home/kde")
|
||||
<< QString::fromLatin1("file:///home/kde/");
|
||||
<< QString::fromLatin1("/home/kde/")
|
||||
<< QString::fromLatin1("/home/kde")
|
||||
<< QString::fromLatin1("/home/kde/");
|
||||
QTest::newRow("local file 3")
|
||||
<< KUrl("file:///home/kde//")
|
||||
<< QString::fromLatin1("file:///home/kde//")
|
||||
<< QString::fromLatin1("file:///home/kde")
|
||||
<< QString::fromLatin1("file:///home/kde//");
|
||||
<< QString::fromLatin1("/home/kde//")
|
||||
<< QString::fromLatin1("/home/kde")
|
||||
<< QString::fromLatin1("/home/kde//");
|
||||
|
||||
QTest::newRow("ftp url")
|
||||
<< KUrl("ftp://ftp.kde.org/")
|
||||
|
@ -275,35 +269,35 @@ void KUrlTest::testToStringList()
|
|||
<< KUrl("ftp://ftp.kde.org/")
|
||||
<< KUrl("ftp://ftp.kde.org///");
|
||||
|
||||
//kDebug() << urls.toStringList(KUrl::LeaveTrailingSlash);
|
||||
// kDebug() << urls.toStringList(KUrl::LeaveTrailingSlash);
|
||||
QCOMPARE(
|
||||
urls.toStringList(KUrl::LeaveTrailingSlash),
|
||||
QStringList()
|
||||
<< QLatin1String("file:///")
|
||||
<< QLatin1String("file:///home/kde/")
|
||||
<< QLatin1String("file:///home/kde//")
|
||||
<< QLatin1String("/")
|
||||
<< QLatin1String("/home/kde/")
|
||||
<< QLatin1String("/home/kde//")
|
||||
<< QLatin1String("ftp://ftp.kde.org/")
|
||||
<< QLatin1String("ftp://ftp.kde.org///")
|
||||
);
|
||||
|
||||
//kDebug() << urls.toStringList(KUrl::RemoveTrailingSlash);
|
||||
// kDebug() << urls.toStringList(KUrl::RemoveTrailingSlash);
|
||||
QCOMPARE(
|
||||
urls.toStringList(KUrl::RemoveTrailingSlash),
|
||||
QStringList()
|
||||
<< QLatin1String("file:///")
|
||||
<< QLatin1String("file:///home/kde")
|
||||
<< QLatin1String("file:///home/kde")
|
||||
<< QLatin1String("/")
|
||||
<< QLatin1String("/home/kde")
|
||||
<< QLatin1String("/home/kde")
|
||||
<< QLatin1String("ftp://ftp.kde.org")
|
||||
<< QLatin1String("ftp://ftp.kde.org")
|
||||
);
|
||||
|
||||
//kDebug() << urls.toStringList(KUrl::AddTrailingSlash);
|
||||
// kDebug() << urls.toStringList(KUrl::AddTrailingSlash);
|
||||
QCOMPARE(
|
||||
urls.toStringList(KUrl::AddTrailingSlash),
|
||||
QStringList()
|
||||
<< QLatin1String("file:///")
|
||||
<< QLatin1String("file:///home/kde/")
|
||||
<< QLatin1String("file:///home/kde//")
|
||||
<< QLatin1String("/")
|
||||
<< QLatin1String("/home/kde/")
|
||||
<< QLatin1String("/home/kde//")
|
||||
<< QLatin1String("ftp://ftp.kde.org/")
|
||||
<< QLatin1String("ftp://ftp.kde.org///")
|
||||
);
|
||||
|
|
|
@ -183,9 +183,9 @@ void KRunUnitTest::testProcessDesktopExecNoFile_data()
|
|||
QTest::newRow("%F l0") << "klauncher4 %F" << l0 << false << klauncher;
|
||||
QTest::newRow("%F l1") << "klauncher4 %F" << l1 << false << QString(klauncher + " /tmp");
|
||||
QTest::newRow("%F l2") << "klauncher4 %F" << l2 << false << QString(kioexec + " 'klauncher4 %F' http://localhost/foo");
|
||||
QTest::newRow("%F l3") << "klauncher4 %F" << l3 << false << QString(kioexec + " 'klauncher4 %F' file:///local/file http://remotehost.org/bar");
|
||||
QTest::newRow("%F l3") << "klauncher4 %F" << l3 << false << QString(kioexec + " 'klauncher4 %F' /local/file http://remotehost.org/bar");
|
||||
|
||||
QTest::newRow("%F l1 tempfile") << "klauncher4 %F" << l1 << true << QString(kioexec + " --tempfiles 'klauncher4 %F' file:///tmp");
|
||||
QTest::newRow("%F l1 tempfile") << "klauncher4 %F" << l1 << true << QString(kioexec + " --tempfiles 'klauncher4 %F' /tmp");
|
||||
|
||||
QTest::newRow("sh -c klauncher4 %F") << "sh -c \"klauncher4 \"'\\\"'\"%F\"'\\\"'"
|
||||
<< l1 << false << QString(m_sh + " -c 'klauncher4 \\\"/tmp\\\"'");
|
||||
|
|
Loading…
Add table
Reference in a new issue