Restore QUrl::setEncodedQuery(QByteArray()) to the Qt4 behavior.
Null bytearray means no query, and QString::fromLatin1(QByteArray()) doesn't give a null string, but an empty string. Same for setEncodedFragment(QByteArray()). Change-Id: I992e9253e35941d66886456872ea06aa2ae92450 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b587da56b9
commit
5ab700f639
@ -294,12 +294,12 @@ public:
|
||||
QT_DEPRECATED QByteArray encodedQuery() const
|
||||
{ return toLatin1_helper(query(FullyEncoded)); }
|
||||
QT_DEPRECATED void setEncodedQuery(const QByteArray &value)
|
||||
{ setQuery(QString::fromLatin1(value)); }
|
||||
{ setQuery(value.isNull() ? QString() : QString::fromLatin1(value)); }
|
||||
|
||||
QT_DEPRECATED QByteArray encodedFragment() const
|
||||
{ return toLatin1_helper(fragment(FullyEncoded)); }
|
||||
QT_DEPRECATED void setEncodedFragment(const QByteArray &value)
|
||||
{ setFragment(QString::fromLatin1(value)); }
|
||||
{ setFragment(value.isNull() ? QString() : QString::fromLatin1(value)); }
|
||||
|
||||
private:
|
||||
// helper function for the encodedQuery and encodedFragment functions
|
||||
|
@ -2167,19 +2167,25 @@ void tst_QUrl::emptyQueryOrFragment()
|
||||
QVERIFY(url.hasQuery());
|
||||
QCOMPARE(url.query(), QString(QLatin1String("abc=def")));
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?abc=def")));
|
||||
url.setEncodedQuery("abc=def");
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?abc=def")));
|
||||
|
||||
// remove encodedQuery
|
||||
url.setQuery(QString());
|
||||
QVERIFY(!url.hasQuery());
|
||||
QVERIFY(url.encodedQuery().isNull());
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz")));
|
||||
url.setEncodedQuery(QByteArray());
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz")));
|
||||
|
||||
// add empty encodedQuery
|
||||
url.setEncodedQuery("");
|
||||
url.setQuery("");
|
||||
QVERIFY(url.hasQuery());
|
||||
QVERIFY(url.encodedQuery().isEmpty());
|
||||
QVERIFY(!url.encodedQuery().isNull());
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?")));
|
||||
url.setEncodedQuery("");
|
||||
QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2217,6 +2223,7 @@ void tst_QUrl::setEncodedFragment_data()
|
||||
QTest::addColumn<QByteArray>("expected");
|
||||
|
||||
typedef QByteArray BA;
|
||||
QTest::newRow("null") << BA("http://www.kde.org") << BA() << BA("http://www.kde.org");
|
||||
QTest::newRow("empty") << BA("http://www.kde.org") << BA("") << BA("http://www.kde.org#");
|
||||
QTest::newRow("basic test") << BA("http://www.kde.org") << BA("abc") << BA("http://www.kde.org#abc");
|
||||
QTest::newRow("initial url has fragment") << BA("http://www.kde.org#old") << BA("new") << BA("http://www.kde.org#new");
|
||||
@ -2234,7 +2241,7 @@ void tst_QUrl::setEncodedFragment()
|
||||
QVERIFY(u.isValid());
|
||||
u.setEncodedFragment(fragment);
|
||||
QVERIFY(u.isValid());
|
||||
QVERIFY(u.hasFragment());
|
||||
QCOMPARE(!fragment.isNull(), u.hasFragment());
|
||||
QCOMPARE(QString::fromLatin1(u.toEncoded()), QString::fromLatin1(expected));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user