From 91596c9c08208690894ec11a3a99eac57ad17f2b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 6 Jan 2011 14:51:04 +0100 Subject: QUrl::setUrl should call detach Task-number: QTBUG-16425 Reviewed-by: Gabriel Reviewed-by: Markus Goetz --- src/corelib/io/qurl.cpp | 1 + tests/auto/qurl/tst_qurl.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 6a3037d..45f908d 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -4262,6 +4262,7 @@ void QUrl::setUrl(const QString &url) */ void QUrl::setUrl(const QString &url, ParsingMode parsingMode) { + detach(); // escape all reserved characters and delimiters // reserved = gen-delims / sub-delims if (parsingMode != TolerantMode) { diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 63f9721..4354ffb 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -675,6 +675,14 @@ void tst_QUrl::setUrl() QCOMPARE(url.encodedPath().constData(), "text/javascript,d5%20%3D%20'five%5Cu0027s'%3B"); } + { //check it calls detach + QUrl u1("http://aaa.com"); + QUrl u2 = u1; + u2.setUrl("http://bbb.com"); + QCOMPARE(u1.host(), QString::fromLatin1("aaa.com")); + QCOMPARE(u2.host(), QString::fromLatin1("bbb.com")); + } + /* The tests below are copied from kdelibs/kdecore/tests/kurltest.cpp (an old version of) -- cgit v0.12