summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-10-29 13:28:42 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-10-29 13:29:44 (GMT)
commitef4276442f8421771c827ad4e29bc69baf24de2d (patch)
treea2344388d7952dca17cab0642717d04698864b2a
parent7e0c0d684a42371c3597441a2488e05ce520f91e (diff)
downloadQt-ef4276442f8421771c827ad4e29bc69baf24de2d.zip
Qt-ef4276442f8421771c827ad4e29bc69baf24de2d.tar.gz
Qt-ef4276442f8421771c827ad4e29bc69baf24de2d.tar.bz2
Remove the fromUserInput implementation and tests.
Reviewed-by: Trust Me
-rw-r--r--src/corelib/io/qurl.cpp119
-rw-r--r--tests/auto/qurl/tst_qurl.cpp55
2 files changed, 46 insertions, 128 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 6001d9d..a865d8d 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -5556,79 +5556,6 @@ QUrl QUrl::fromEncoded(const QByteArray &input, ParsingMode parsingMode)
}
/*!
- Returns a valid URL from a user supplied \a userInput string if one can be
- deducted. In the case that is not possible, an invalid QUrl() is returned.
-
- \since 4.6
-
- Most applications that can browse the web, allow the user to input a URL
- in the form of a plain string. This string can be manually typed into
- a location bar, obtained from the clipboard, or passed in via command
- line arguments.
-
- When the string is not already a valid URL, a best guess is performed,
- making various web related assumptions.
-
- In the case the string corresponds to a valid file path on the system,
- a file:// URL is constructed, using QUrl::fromLocalFile().
-
- If that is not the case, an attempt is made to turn the string into a
- http:// or ftp:// URL. The latter in the case the string starts with
- 'ftp'. The result is then passed through QUrl's tolerant parser, and
- in the case or success, a valid QUrl is returned, or else a QUrl().
-
- \section1 Examples:
-
- \list
- \o qt.nokia.com becomes http://qt.nokia.com
- \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com
- \o localhost becomes http://localhost
- \o /home/user/test.html becomes file:///home/user/test.html (if exists)
- \endlist
-
- \section2 Tips to avoid erroneous character conversion when dealing with
- URLs and strings:
-
- \list
- \o When creating an URL QString from a QByteArray or a char*, always use
- QString::fromUtf8().
- \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of
- QUrl(string) and QUrl::toString() when converting QUrl to/from string.
- \endlist
-*/
-QUrl QUrl::fromUserInput(const QString &userInput)
-{
- QString trimmedString = userInput.trimmed();
-
- // Absolute files
- if (QDir::isAbsolutePath(trimmedString))
- return QUrl::fromLocalFile(trimmedString);
-
- // Check the most common case of a valid url with scheme and host first
- QUrl url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
- if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty())
- return url;
-
- // If the string is missing the scheme or the scheme is not valid, prepend a scheme
- QString scheme = url.scheme();
- if (scheme.isEmpty() || scheme.contains(QLatin1Char('.')) || scheme == QLatin1String("localhost")) {
- // Do not do anything for strings such as "foo", only "foo.com"
- int dotIndex = trimmedString.indexOf(QLatin1Char('.'));
- if (dotIndex != -1 || trimmedString.startsWith(QLatin1String("localhost"))) {
- const QString hostscheme = trimmedString.left(dotIndex).toLower();
- QByteArray scheme = (hostscheme == QLatin1String("ftp")) ? "ftp" : "http";
- trimmedString = QLatin1String(scheme) + QLatin1String("://") + trimmedString;
- }
- url = QUrl::fromEncoded(trimmedString.toUtf8(), QUrl::TolerantMode);
- }
-
- if (url.isValid())
- return url;
-
- return QUrl();
-}
-
-/*!
Returns a decoded copy of \a input. \a input is first decoded from
percent encoding, then converted from UTF-8 to unicode.
*/
@@ -6227,4 +6154,50 @@ QString QUrl::errorString() const
\internal
*/
+
+/*!
+ Returns a valid URL from a user supplied \a userInput string if one can be
+ deducted. In the case that is not possible, an invalid QUrl() is returned.
+
+ \since 4.6
+
+ Most applications that can browse the web, allow the user to input a URL
+ in the form of a plain string. This string can be manually typed into
+ a location bar, obtained from the clipboard, or passed in via command
+ line arguments.
+
+ When the string is not already a valid URL, a best guess is performed,
+ making various web related assumptions.
+
+ In the case the string corresponds to a valid file path on the system,
+ a file:// URL is constructed, using QUrl::fromLocalFile().
+
+ If that is not the case, an attempt is made to turn the string into a
+ http:// or ftp:// URL. The latter in the case the string starts with
+ 'ftp'. The result is then passed through QUrl's tolerant parser, and
+ in the case or success, a valid QUrl is returned, or else a QUrl().
+
+ \section1 Examples:
+
+ \list
+ \o qt.nokia.com becomes http://qt.nokia.com
+ \o ftp.qt.nokia.com becomes ftp://ftp.qt.nokia.com
+ \o localhost becomes http://localhost
+ \o /home/user/test.html becomes file:///home/user/test.html (if exists)
+ \endlist
+
+ \section2 Tips to avoid erroneous character conversion when dealing with
+ URLs and strings:
+
+ \list
+ \o When creating an URL QString from a QByteArray or a char*, always use
+ QString::fromUtf8().
+ \o Favor the use of QUrl::fromEncoded() and QUrl::toEncoded() instead of
+ QUrl(string) and QUrl::toString() when converting QUrl to/from string.
+ \endlist
+*/
+QUrl QUrl::fromUserInput(const QString &userInput)
+{
+}
+
QT_END_NAMESPACE
diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp
index 72c13bf..178e5e5 100644
--- a/tests/auto/qurl/tst_qurl.cpp
+++ b/tests/auto/qurl/tst_qurl.cpp
@@ -3679,65 +3679,10 @@ void tst_QUrl::binaryData()
void tst_QUrl::fromUserInput_data()
{
- QTest::addColumn<QString>("string");
- QTest::addColumn<QUrl>("url");
-
- // Null
- QTest::newRow("null") << QString() << QUrl();
-
- // File
- QDirIterator it(QDir::homePath());
- QString fileString;
- int c = 0;
- while (it.hasNext()) {
- it.next();
- QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath());
- }
-
- // basic latin1
- QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode);
- // unicode
- QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode);
-
- // no scheme
- QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org");
- QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org");
- QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org");
- QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit");
-
- // QUrl's tolerant parser should already handle this
- QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html");
-
- // Make sure the :80, i.e. port doesn't screw anything up
- QUrl portUrl("http://webkit.org");
- portUrl.setPort(80);
- QTest::newRow("port-0") << "webkit.org:80" << portUrl;
- QTest::newRow("port-1") << "http://webkit.org:80" << portUrl;
-
- // mailto doesn't have a ://, but is valid
- QUrl mailto("somebody@somewhere.net");
- mailto.setScheme("mailto");
- QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto;
-
- // misc
- QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost");
- QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80");
- QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html");
- QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor");
-
- // FYI: The scheme in the resulting url user
- QUrl authUrl("user:pass@domain.com");
- QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl;
}
-// public static QUrl guessUrlFromString(QString const& string)
void tst_QUrl::fromUserInput()
{
- QFETCH(QString, string);
- QFETCH(QUrl, url);
-
- QUrl guessedUrl = QUrl::fromUserInput(string);
- QCOMPARE(guessedUrl, url);
}
void tst_QUrl::task_199967()