1407 } |
1408 } |
1408 |
1409 |
1409 void tst_QUrl::i18n_data() |
1410 void tst_QUrl::i18n_data() |
1410 { |
1411 { |
1411 QTest::addColumn<QString>("input"); |
1412 QTest::addColumn<QString>("input"); |
1412 QTest::addColumn<QByteArray>("punyOutput"); |
1413 QTest::addColumn<QByteArray>("punyOutput"); |
1413 |
1414 |
1414 QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top") |
1415 QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top") |
1415 << QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top"); |
1416 << QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top"); |
1416 QTest::newRow("räksmörgås") << QString::fromLatin1("http://www.räksmörgås.no/") |
1417 QTest::newRow("räksmörgås") << QString::fromLatin1("http://www.räksmörgås.no/") |
1417 << QByteArray("http://www.xn--rksmrgs-5wao1o.no/"); |
1418 << QByteArray("http://www.xn--rksmrgs-5wao1o.no/"); |
2158 QTest::addColumn<QByteArray>("encoded"); |
2163 QTest::addColumn<QByteArray>("encoded"); |
2159 QTest::addColumn<QByteArray>("excludeInEncoding"); |
2164 QTest::addColumn<QByteArray>("excludeInEncoding"); |
2160 QTest::addColumn<QByteArray>("includeInEncoding"); |
2165 QTest::addColumn<QByteArray>("includeInEncoding"); |
2161 |
2166 |
2162 QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
2167 QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
2163 << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
2168 << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
2164 << QByteArray("") |
2169 << QByteArray("") |
2165 << QByteArray(""); |
2170 << QByteArray(""); |
2166 QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}") |
2171 QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}") |
2167 << QByteArray("%7B%09%0A%0D%5E%22abc%7D") |
2172 << QByteArray("%7B%09%0A%0D%5E%22abc%7D") |
2168 << QByteArray("") |
2173 << QByteArray("") |
2169 << QByteArray(""); |
2174 << QByteArray(""); |
2170 QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
2175 QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
2171 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") |
2176 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") |
2172 << QByteArray("") |
2177 << QByteArray("") |
2173 << QByteArray(""); |
2178 << QByteArray(""); |
2174 QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
2179 QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
2175 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") |
2180 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") |
2176 << QByteArray("!$&'()*+,;=") |
2181 << QByteArray("!$&'()*+,;=") |
2177 << QByteArray(""); |
2182 << QByteArray(""); |
2178 QTest::newRow("test_05") << QString::fromLatin1("abcd") |
2183 QTest::newRow("test_05") << QString::fromLatin1("abcd") |
2179 << QByteArray("a%62%63d") |
2184 << QByteArray("a%62%63d") |
2180 << QByteArray("") |
2185 << QByteArray("") |
2181 << QByteArray("bc"); |
2186 << QByteArray("bc"); |
2182 } |
2187 } |
2183 |
2188 |
2184 void tst_QUrl::toPercentEncoding() |
2189 void tst_QUrl::toPercentEncoding() |
2185 { |
2190 { |
2186 QFETCH(QString, original); |
2191 QFETCH(QString, original); |
2187 QFETCH(QByteArray, encoded); |
2192 QFETCH(QByteArray, encoded); |
2188 QFETCH(QByteArray, excludeInEncoding); |
2193 QFETCH(QByteArray, excludeInEncoding); |
2189 QFETCH(QByteArray, includeInEncoding); |
2194 QFETCH(QByteArray, includeInEncoding); |
2190 |
2195 |
2191 QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); |
2196 QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); |
2192 QCOMPARE(encodedUrl.constData(), encoded.constData()); |
2197 QCOMPARE(encodedUrl.constData(), encoded.constData()); |
2193 QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl)); |
2198 QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl)); |
2194 } |
2199 } |
2195 |
2200 |
2196 void tst_QUrl::symmetry() |
2201 void tst_QUrl::symmetry() |
2454 } |
2459 } |
2455 { |
2460 { |
2456 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode); |
2461 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode); |
2457 QVERIFY(!url.isValid()); |
2462 QVERIFY(!url.isValid()); |
2458 // < and > are not allowed in userinfo in strict mode |
2463 // < and > are not allowed in userinfo in strict mode |
|
2464 url.setUserName("normal_username"); |
|
2465 QVERIFY(url.isValid()); |
2459 } |
2466 } |
2460 { |
2467 { |
2461 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/"); |
2468 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/"); |
2462 QVERIFY(url.isValid()); |
2469 QVERIFY(url.isValid()); |
2463 // < and > are allowed in tolerant mode |
2470 // < and > are allowed in tolerant mode |
2464 } |
2471 } |
2465 { |
2472 { |
2466 QUrl url = QUrl::fromEncoded("http://strange;hostname/here"); |
2473 QUrl url = QUrl::fromEncoded("http://strange;hostname/here"); |
2467 QVERIFY(!url.isValid()); |
2474 QVERIFY(!url.isValid()); |
2468 QCOMPARE(url.path(), QString("/here")); |
2475 QCOMPARE(url.path(), QString("/here")); |
2469 } |
2476 url.setAuthority("foobar@bar"); |
|
2477 QVERIFY(url.isValid()); |
|
2478 } |
|
2479 |
|
2480 { |
|
2481 QUrl url = QUrl::fromEncoded("foo://stuff;1/g"); |
|
2482 QVERIFY(!url.isValid()); |
|
2483 QCOMPARE(url.path(), QString("/g")); |
|
2484 url.setHost("stuff-1"); |
|
2485 QVERIFY(url.isValid()); |
|
2486 } |
|
2487 |
2470 } |
2488 } |
2471 |
2489 |
2472 void tst_QUrl::schemeValidator_data() |
2490 void tst_QUrl::schemeValidator_data() |
2473 { |
2491 { |
2474 QTest::addColumn<QByteArray>("encodedUrl"); |
2492 QTest::addColumn<QByteArray>("encodedUrl"); |
3187 << QString::fromLatin1("alqualond\353") |
3205 << QString::fromLatin1("alqualond\353") |
3188 << QString::fromLatin1("alqualond\353"); |
3206 << QString::fromLatin1("alqualond\353"); |
3189 |
3207 |
3190 QTest::newRow("separator-3002") << QString::fromUtf8("example\343\200\202com") |
3208 QTest::newRow("separator-3002") << QString::fromUtf8("example\343\200\202com") |
3191 << "example.com" << "." << "example.com"; |
3209 << "example.com" << "." << "example.com"; |
|
3210 |
|
3211 QString egyptianIDN = |
|
3212 QString::fromUtf8("\331\210\330\262\330\247\330\261\330\251\055\330\247\331\204\330" |
|
3213 "\243\330\252\330\265\330\247\331\204\330\247\330\252.\331\205" |
|
3214 "\330\265\330\261"); |
|
3215 QTest::newRow("egyptian-tld-ace") |
|
3216 << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c" |
|
3217 << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c" |
|
3218 << "." |
|
3219 << egyptianIDN; |
|
3220 QTest::newRow("egyptian-tld-unicode") |
|
3221 << egyptianIDN |
|
3222 << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c" |
|
3223 << "." |
|
3224 << egyptianIDN; |
|
3225 QTest::newRow("egyptian-tld-mix1") |
|
3226 << QString::fromUtf8("\331\210\330\262\330\247\330\261\330\251\055\330\247\331\204\330" |
|
3227 "\243\330\252\330\265\330\247\331\204\330\247\330\252.xn--wgbh1c") |
|
3228 << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c" |
|
3229 << "." |
|
3230 << egyptianIDN; |
|
3231 QTest::newRow("egyptian-tld-mix2") |
|
3232 << QString::fromUtf8("xn----rmckbbajlc6dj7bxne2c.\331\205\330\265\330\261") |
|
3233 << "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c" |
|
3234 << "." |
|
3235 << egyptianIDN; |
3192 } |
3236 } |
3193 |
3237 |
3194 void tst_QUrl::ace_testsuite() |
3238 void tst_QUrl::ace_testsuite() |
3195 { |
3239 { |
3196 static const char canonsuffix[] = ".troll.no"; |
3240 static const char canonsuffix[] = ".troll.no"; |
3241 QTest::newRow("slash") << "foo/bar" << true; |
3285 QTest::newRow("slash") << "foo/bar" << true; |
3242 QTest::newRow("colon") << "foo:80" << true; |
3286 QTest::newRow("colon") << "foo:80" << true; |
3243 QTest::newRow("question") << "foo?bar" << true; |
3287 QTest::newRow("question") << "foo?bar" << true; |
3244 QTest::newRow("at") << "foo@bar" << true; |
3288 QTest::newRow("at") << "foo@bar" << true; |
3245 QTest::newRow("backslash") << "foo\\bar" << false; |
3289 QTest::newRow("backslash") << "foo\\bar" << false; |
3246 QTest::newRow("underline") << "foo_bar" << false; |
|
3247 |
3290 |
3248 // these characters are transformed by NFKC to non-LDH characters |
3291 // these characters are transformed by NFKC to non-LDH characters |
3249 QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false; // U+2024 ONE DOT LEADER |
3292 QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false; // U+2024 ONE DOT LEADER |
3250 QTest::newRow("slash-like") << QString::fromUtf8("foo\357\274\217bar") << false; // U+FF0F FULLWIDTH SOLIDUS |
3293 QTest::newRow("slash-like") << QString::fromUtf8("foo\357\274\217bar") << false; // U+FF0F FULLWIDTH SOLIDUS |
3251 |
3294 |
3858 << QUrl::fromEncoded("http://www.foo.com:8080/") |
3902 << QUrl::fromEncoded("http://www.foo.com:8080/") |
3859 << QUrl::fromEncoded("newfile.html") |
3903 << QUrl::fromEncoded("newfile.html") |
3860 << QUrl::fromEncoded("http://www.foo.com:8080/newfile.html"); |
3904 << QUrl::fromEncoded("http://www.foo.com:8080/newfile.html"); |
3861 } |
3905 } |
3862 |
3906 |
|
3907 void tst_QUrl::taskQTBUG_6962() |
|
3908 { |
|
3909 //bug 6962: empty authority ignored by setAuthority |
|
3910 QUrl url("http://example.com/something"); |
|
3911 url.setAuthority(QString()); |
|
3912 QCOMPARE(url.authority(), QString()); |
|
3913 } |
|
3914 |
3863 QTEST_MAIN(tst_QUrl) |
3915 QTEST_MAIN(tst_QUrl) |
3864 #include "tst_qurl.moc" |
3916 #include "tst_qurl.moc" |