mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdecore: add KUrl query and fragment test
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
67d6fa8588
commit
ef02376c35
3 changed files with 67 additions and 2 deletions
|
@ -40,10 +40,26 @@
|
|||
#include <QtCore/QMimeData>
|
||||
#include <QtNetwork/QHostInfo>
|
||||
|
||||
// static const int kurlDebugArea = 181; // see kdebug.areas
|
||||
|
||||
static const char s_kdeUriListMime[] = "application/x-kde4-urilist";
|
||||
|
||||
// FIXME: using local files to pass around queries and fragments is tottaly bonkers, this will make
|
||||
// sure they are not a thing
|
||||
// #define KURL_COMPAT_CHECK
|
||||
|
||||
#ifdef KURL_COMPAT_CHECK
|
||||
static const int kurlDebugArea = 181; // see kdebug.areas
|
||||
|
||||
void kCheckLocalFile(KUrl *kurl)
|
||||
{
|
||||
if (kurl->isLocalFile()) {
|
||||
const QString kurlstring = kurl->url();
|
||||
if (kurlstring.contains(QLatin1Char('?')) || kurlstring.contains(QLatin1Char('#'))) {
|
||||
kFatal(kurlDebugArea) << "Query or fragment detected in" << kurlstring;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static QByteArray uriListData(const KUrl::List &urls)
|
||||
{
|
||||
QByteArray result;
|
||||
|
@ -812,6 +828,9 @@ void KUrl::setPath(const QString &_path)
|
|||
if (path.isEmpty()) {
|
||||
path = _path;
|
||||
}
|
||||
#ifdef KURL_COMPAT_CHECK
|
||||
kCheckLocalFile(this);
|
||||
#endif
|
||||
QUrl::setPath(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,50 @@ QTEST_KDEMAIN_CORE(KUrlTest)
|
|||
|
||||
Q_DECLARE_METATYPE(KUrl::EqualsOptions);
|
||||
|
||||
|
||||
void KUrlTest::testQueryAndFragment_data()
|
||||
{
|
||||
QTest::addColumn<KUrl>("url" );
|
||||
QTest::addColumn<QString>("query");
|
||||
QTest::addColumn<QString>("fragment");
|
||||
|
||||
QTest::newRow("local file 1")
|
||||
<< KUrl("file:///")
|
||||
<< QString()
|
||||
<< QString();
|
||||
QTest::newRow("local file 1 - with query and fragment")
|
||||
<< KUrl("file:///?foo=bar#baz")
|
||||
<< QString::fromLatin1("foo=bar")
|
||||
<< QString::fromLatin1("baz");
|
||||
QTest::newRow("local file 2")
|
||||
<< KUrl("file:///home/kde/?foo=bar#baz")
|
||||
<< QString::fromLatin1("foo=bar")
|
||||
<< QString::fromLatin1("baz");
|
||||
QTest::newRow("local file 3")
|
||||
<< KUrl("kde//?foo=bar#baz")
|
||||
<< QString::fromLatin1("foo=bar")
|
||||
<< QString::fromLatin1("baz");
|
||||
// NOTE: not supported and will trigger the warning in KUrl
|
||||
QTest::newRow("local file 4")
|
||||
<< KUrl("/foo?bar=baz#foobar")
|
||||
<< QString()
|
||||
<< QString();
|
||||
QTest::newRow("ftp url - 3 trailing slashes")
|
||||
<< KUrl("ftp://ftp.kde.org///?foo=bar#baz")
|
||||
<< QString::fromLatin1("foo=bar")
|
||||
<< QString::fromLatin1("baz");
|
||||
}
|
||||
|
||||
void KUrlTest::testQueryAndFragment()
|
||||
{
|
||||
QFETCH(KUrl, url);
|
||||
QFETCH(QString, query);
|
||||
QFETCH(QString, fragment);
|
||||
|
||||
QCOMPARE(url.query(), query);
|
||||
QCOMPARE(url.fragment(), fragment);
|
||||
}
|
||||
|
||||
void KUrlTest::testcleanPath_data()
|
||||
{
|
||||
QTest::addColumn<KUrl>("url" );
|
||||
|
|
|
@ -25,6 +25,8 @@ class KUrlTest : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void testQueryAndFragment_data();
|
||||
void testQueryAndFragment();
|
||||
void testcleanPath_data();
|
||||
void testcleanPath();
|
||||
void testEquals_data();
|
||||
|
|
Loading…
Add table
Reference in a new issue