aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/uriparser/test
diff options
context:
space:
mode:
authororivej <orivej@yandex-team.ru>2022-02-10 16:45:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:01 +0300
commit2d37894b1b037cf24231090eda8589bbb44fb6fc (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/restricted/uriparser/test
parent718c552901d703c502ccbefdfc3c9028d608b947 (diff)
downloadydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/uriparser/test')
-rw-r--r--contrib/restricted/uriparser/test/FourSuite.cpp1264
-rw-r--r--contrib/restricted/uriparser/test/MemoryManagerSuite.cpp640
-rw-r--r--contrib/restricted/uriparser/test/VersionSuite.cpp86
-rw-r--r--contrib/restricted/uriparser/test/test.cpp4462
-rw-r--r--contrib/restricted/uriparser/test/ya.make36
5 files changed, 3244 insertions, 3244 deletions
diff --git a/contrib/restricted/uriparser/test/FourSuite.cpp b/contrib/restricted/uriparser/test/FourSuite.cpp
index a06434613e..466a94cb67 100644
--- a/contrib/restricted/uriparser/test/FourSuite.cpp
+++ b/contrib/restricted/uriparser/test/FourSuite.cpp
@@ -1,632 +1,632 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
- * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <gtest/gtest.h>
-
-#include <uriparser/Uri.h>
-
-
-
-// All testcases in this file are coming from
-// http://cvs.4suite.org/viewcvs/4Suite/test/Lib/test_uri.py
-
-
-namespace {
-
-bool testAddOrRemoveBaseHelper(const char * ref, const char * base,
- const char * expected, bool add = true, bool domainRootMode = false) {
- UriParserStateA stateA;
-
- // Base
- UriUriA baseUri;
- stateA.uri = &baseUri;
- int res = uriParseUriA(&stateA, base);
- if (res != 0) {
- return false;
- }
-
- // Rel
- UriUriA relUri;
- stateA.uri = &relUri;
- res = uriParseUriA(&stateA, ref);
- if (res != 0) {
- uriFreeUriMembersA(&baseUri);
- return false;
- }
-
- // Expected result
- UriUriA expectedUri;
- stateA.uri = &expectedUri;
- res = uriParseUriA(&stateA, expected);
- if (res != 0) {
- uriFreeUriMembersA(&baseUri);
- uriFreeUriMembersA(&relUri);
- uriFreeUriMembersA(&expectedUri);
- return false;
- }
-
- // Transform
- UriUriA transformedUri;
- if (add) {
- res = uriAddBaseUriA(&transformedUri, &relUri, &baseUri);
- } else {
- res = uriRemoveBaseUriA(&transformedUri, &relUri, &baseUri,
- domainRootMode ? URI_TRUE : URI_FALSE);
- }
- if (res != 0) {
- uriFreeUriMembersA(&baseUri);
- uriFreeUriMembersA(&relUri);
- uriFreeUriMembersA(&expectedUri);
- uriFreeUriMembersA(&transformedUri);
- return false;
- }
-
- const bool equal = (URI_TRUE == uriEqualsUriA(&transformedUri, &expectedUri));
- if (!equal) {
- char transformedUriText[1024 * 8];
- char expectedUriText[1024 * 8];
- uriToStringA(transformedUriText, &transformedUri, 1024 * 8, NULL);
- uriToStringA(expectedUriText, &expectedUri, 1024 * 8, NULL);
- printf("\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
- }
-
- uriFreeUriMembersA(&baseUri);
- uriFreeUriMembersA(&relUri);
- uriFreeUriMembersA(&expectedUri);
- uriFreeUriMembersA(&transformedUri);
- return equal;
-}
-
-} // namespace
-
-
-TEST(FourSuite, AbsolutizeTestCases) {
- const char * const BASE_URI[] = {
- "http://a/b/c/d;p?q",
- "http://a/b/c/d;p?q=1/2",
- "http://a/b/c/d;p=1/2?q",
- "fred:///s//a/b/c",
- "http:///s//a/b/c"};
-
- // ref, base, exptected
-
- // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../c", "foo:a/b", "foo:c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("foo:.", "foo:a", "foo:"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../../../bar", "zz:abc", "zz:/bar"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../bar", "zz:abc", "zz:/bar"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../../../bar", "zz:abc", "zz:bar"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../bar", "zz:abc", "zz:bar"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("zz:.", "zz:abc", "zz:"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/.", BASE_URI[0], "http://a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/.foo", BASE_URI[0], "http://a/.foo"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(".foo", BASE_URI[0], "http://a/b/c/.foo"));
-
- // http://gbiv.com/protocols/uri/test/rel_examples1.html
- // examples from RFC 2396
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[0], "g:h"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[0], "http://a/b/c/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[0], "http://a/b/c/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[0], "http://a/b/c/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[0], "http://a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[0], "http://g"));
-
- // changed with RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[0], "http://a/b/c/d;p?y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[0], "http://a/b/c/g?y"));
-
- // changed with RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("#s", BASE_URI[0], "http://a/b/c/d;p?q#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[0], "http://a/b/c/g#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y#s", BASE_URI[0], "http://a/b/c/g?y#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[0], "http://a/b/c/;x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[0], "http://a/b/c/g;x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x?y#s", BASE_URI[0], "http://a/b/c/g;x?y#s"));
-
- // changed with RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", BASE_URI[0], "http://a/b/c/d;p?q"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(".", BASE_URI[0], "http://a/b/c/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[0], "http://a/b/c/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("..", BASE_URI[0], "http://a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[0], "http://a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[0], "http://a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../..", BASE_URI[0], "http://a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[0], "http://a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[0], "http://a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[0], "http://a/g")); // http://a/../g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[0], "http://a/g")); // http://a/../../g
-
- // changed with RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/./g", BASE_URI[0], "http://a/g"));
-
- // changed with RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/../g", BASE_URI[0], "http://a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g.", BASE_URI[0], "http://a/b/c/g."));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(".g", BASE_URI[0], "http://a/b/c/.g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g..", BASE_URI[0], "http://a/b/c/g.."));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("..g", BASE_URI[0], "http://a/b/c/..g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./../g", BASE_URI[0], "http://a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g/.", BASE_URI[0], "http://a/b/c/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/./h", BASE_URI[0], "http://a/b/c/g/h"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/../h", BASE_URI[0], "http://a/b/c/h"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[0], "http://a/b/c/g;x=1/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[0], "http://a/b/c/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[0], "http://a/b/c/g?y/./x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[0], "http://a/b/c/g?y/../x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[0], "http://a/b/c/g#s/./x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[0], "http://a/b/c/g#s/../x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http:g", BASE_URI[0], "http:g")); // http://a/b/c/g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http:", BASE_URI[0], "http:")); // BASE_URI[0]
-
- // not sure where this one originated
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/a/b/c/./../../g", BASE_URI[0], "http://a/a/g"));
-
- // http://gbiv.com/protocols/uri/test/rel_examples2.html
- // slashes in base URI's query args
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[1], "http://a/b/c/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[1], "http://a/b/c/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[1], "http://a/b/c/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[1], "http://a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[1], "http://g"));
-
- // changed in RFC 2396bis
- // ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/?y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/d;p?y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[1], "http://a/b/c/g?y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[1], "http://a/b/c/g?y/./x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[1], "http://a/b/c/g?y/../x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[1], "http://a/b/c/g#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[1], "http://a/b/c/g#s/./x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[1], "http://a/b/c/g#s/../x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[1], "http://a/b/c/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[1], "http://a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[1], "http://a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[1], "http://a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[1], "http://a/g"));
-
- // http://gbiv.com/protocols/uri/test/rel_examples3.html
- // slashes in path params
- // all of these changed in RFC 2396bis
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[2], "http://a/b/c/d;p=1/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[2], "http://a/b/c/d;p=1/g?y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[2], "http://a/b/c/d;p=1/;x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[2], "http://a/b/c/d;p=1/g;x"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[2], "http://a/b/c/d;p=1/g;x=1/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[2], "http://a/b/c/d;p=1/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[2], "http://a/b/c/d;p=1/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[2], "http://a/b/c/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[2], "http://a/b/c/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[2], "http://a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[2], "http://a/b/g"));
-
- // http://gbiv.com/protocols/uri/test/rel_examples4.html
- // double and triple slash, unknown scheme
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[3], "g:h"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[3], "fred:///s//a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[3], "fred:///s//a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[3], "fred:///s//a/b/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[3], "fred://g")); // may change to fred:///s//g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[3], "fred://g/x")); // may change to fred:///s//g/x
- ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[3], "fred:///g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[3], "fred:///s//a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[3], "fred:///s//a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[3], "fred:///s//a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[3], "fred:///s//")); // may change to fred:///s//a/../
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[3], "fred:///s//g")); // may change to fred:///s//a/../g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[3], "fred:///s/g")); // may change to fred:///s//a/../../g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/../../../g
-
- // http://gbiv.com/protocols/uri/test/rel_examples5.html
- // double and triple slash, well-known scheme
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[4], "g:h"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[4], "http:///s//a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[4], "http:///s//a/b/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[4], "http:///s//a/b/g/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[4], "http:///g")); // may change to http:///s//a/g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[4], "http://g")); // may change to http:///s//g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[4], "http://g/x")); // may change to http:///s//g/x
- ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[4], "http:///g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[4], "http:///s//a/b/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[4], "http:///s//a/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[4], "http:///s//a/g"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[4], "http:///s//")); // may change to http:///s//a/../
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[4], "http:///s//g")); // may change to http:///s//a/../g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[4], "http:///s/g")); // may change to http:///s//a/../../g
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[4], "http:///g")); // may change to http:///s//a/../../../g
-
- // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
- ASSERT_TRUE(testAddOrRemoveBaseHelper("bar:abc", "foo:xyz", "bar:abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "http://example/x/y/z", "http://example/x/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/x/abc", "http://example2/x/y/z", "http://example/x/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "http://ex/x/y/z", "http://ex/x/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "http://ex/x/y", "http://ex/x/q/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "http://ex/x/y", "http://ex/x/q/r#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "http://ex/x/y", "http://ex/x/q/r#s/t"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "http://ex/x/y", "ftp://ex/x/q/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y", "http://ex/x/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/", "http://ex/x/y/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/pdq", "http://ex/x/y/pdq"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "http://ex/x/y/", "http://ex/x/y/z/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("#Animal", "file:/swap/test/animal.rdf", "file:/swap/test/animal.rdf#Animal"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "file:/e/x/y/z", "file:/e/x/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/example/x/abc", "file:/example2/x/y/z", "file:/example/x/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "file:/ex/x/y/z", "file:/ex/x/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/r", "file:/ex/x/y/z", "file:/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "file:/ex/x/y", "file:/ex/x/q/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "file:/ex/x/y", "file:/ex/x/q/r#s"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#", "file:/ex/x/y", "file:/ex/x/q/r#"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "file:/ex/x/y", "file:/ex/x/q/r#s/t"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "file:/ex/x/y", "ftp://ex/x/q/r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y", "file:/ex/x/y"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/", "file:/ex/x/y/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/pdq", "file:/ex/x/y/pdq"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "file:/ex/x/y/", "file:/ex/x/y/z/"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/devel/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./#blort", "file:/some/dir/foo", "file:/some/dir/#blort"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./#", "file:/some/dir/foo", "file:/some/dir/#"));
-
- // Ryan Lee
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./", "http://example/x/abc.efg", "http://example/x/"));
-
- // Graham Klyne's tests
- // http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls
- // 01-31 are from Connelly's cases
-
- // 32-49
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./q:r", "http://ex/x/y", "http://ex/x/q:r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./p=q:r", "http://ex/x/y", "http://ex/x/p=q:r"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("?pp/rr", "http://ex/x/y?pp/qq", "http://ex/x/y?pp/rr"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("y/z", "http://ex/x/y?pp/qq", "http://ex/x/y/z"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("local/qual@domain.org#frag", "mailto:local", "mailto:local/qual@domain.org#frag"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("more/qual2@domain2.org#frag", "mailto:local/qual1@domain1.org", "mailto:local/more/qual2@domain2.org#frag"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("y?q", "http://ex/x/y?q", "http://ex/x/y?q"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/x/y?q", "http://ex?p", "http://ex/x/y?q"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("c/d", "foo:a/b", "foo:a/c/d"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/c/d", "foo:a/b", "foo:/c/d"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("", "foo:a/b?c#d", "foo:a/b?c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c", "foo:a", "foo:b/c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:/a/y/z", "foo:/a/b/c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("./b/c", "foo:a", "foo:b/c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/./b/c", "foo:a", "foo:/b/c"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../d", "foo://a//b/c", "foo://a/d"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper(".", "foo:a", "foo:"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("..", "foo:a", "foo:"));
-
- // 50-57 (cf. TimBL comments --
- // http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,
- // http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)
- ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x/y%2Fz", "http://example/x/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../../x%2Fabc", "http://example/a/x/y/z", "http://example/a/x%2Fabc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../x%2Fabc", "http://example/a/x/y%2Fz", "http://example/a/x%2Fabc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x%2Fy/z", "http://example/x%2Fy/abc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("q%3Ar", "http://ex/x/y", "http://ex/x/q%3Ar"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y/z", "http://example/x%2Fabc"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
-
- // 70-77
- ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2", "mailto:local1@domain1?query1", "mailto:local2@domain2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1", "mailto:local2@domain2?query2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1?query1", "mailto:local2@domain2?query2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("local@domain?query2", "mailto:?query1", "mailto:local@domain?query2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b?c/../d", "foo:bar", "http://example/a/b?c/../d"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b#c/../d", "foo:bar", "http://example/a/b#c/../d"));
-
- // 82-88
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http://example.org/base/uri", "http:this"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http:base", "http:this"));
- // Whole in the URI spec, see http://lists.w3.org/Archives/Public/uri/2007Aug/0003.html
- // ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f://g")); // ORIGINAL
- ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f:/.//g")); // FIXED ONE
- ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c//d/e", "f://example.org/base/a", "f://example.org/base/b/c//d/e"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("m2@example.ord/c2@example.org", "mid:m@example.ord/c@example.org", "mid:m@example.ord/m2@example.ord/c2@example.org"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("mini1.xml", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml"));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:a/y/z", "foo:a/b/c"));
-}
-
-
-
-TEST(FourSuite, RelativizeTestCases) {
- const bool REMOVE_MODE = false;
- const bool DOMAIN_ROOT_MODE = true;
-
- // to convert, base, exptected
-
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d", "b/c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/b/c", "s://ex/a/d", "/b/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/b/", "c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://other.ex/a/b/", "s://ex/a/d", "//other.ex/a/b/", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://other.ex/a/d", "//ex/a/b/c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("t://ex/a/b/c", "s://ex/a/d", "t://ex/a/b/c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "t://ex/a/d", "s://ex/a/b/c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a", "s://ex/b/c/d", "/a", REMOVE_MODE, DOMAIN_ROOT_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/c/d", "s://ex/a", "b/c/d", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h", "s://ex/a/d?w", "b/c?h", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c#h", "s://ex/a/d#w", "b/c#h", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h#i", "s://ex/a/d?w#j", "b/c?h#i", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a#i", "s://ex/a", "#i", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a?i", "s://ex/a", "?i", REMOVE_MODE));
-
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/b/", "", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a/b", "", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/", "s://ex/", "", REMOVE_MODE));
-
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d/c", "../b/c", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/", "s://ex/a/d/c", "../b/c/", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/d", "s://ex/a/d/c/d", "../../b/c/d", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/d/e/f", "/a/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/c/d/e", "../../b/", REMOVE_MODE));
-
- // Some tests to ensure that empty path segments don't cause problems.
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a//b/c", "../../b", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a///b", "s://ex/a/", ".///b", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/", "s://ex/a///b", "../../", REMOVE_MODE));
- ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a//b/c", "s://ex/a/b", ".//b/c", REMOVE_MODE));
-}
-
-
-namespace {
-
-int testParseUri(const char * uriText, const char ** expectedErrorPos = NULL) {
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
- int res = uriParseUriA(&state, uriText);
- if (expectedErrorPos != NULL) {
- *expectedErrorPos = state.errorPos;
- }
- uriFreeUriMembersA(&uri);
- return res;
-}
-
-
-
-bool testGoodUri(const char * uriText) {
- return (testParseUri(uriText) == 0);
-}
-
-
-
-bool testBadUri(const char * uriText, int expectedErrorOffset = -1) {
- const char * errorPos = NULL;
- const int ret = testParseUri(uriText, &errorPos);
- return ((ret == URI_ERROR_SYNTAX)
- && (errorPos != NULL)
- && (
- (expectedErrorOffset == -1)
- || (errorPos == (uriText + expectedErrorOffset))
- ));
-}
-
-} // namespace
-
-
-
-TEST(FourSuite, GoodUriReferences) {
- ASSERT_TRUE(testGoodUri("file:///foo/bar"));
- ASSERT_TRUE(testGoodUri("mailto:user@host?subject=blah"));
- ASSERT_TRUE(testGoodUri("dav:")); // empty opaque part / rel-path allowed by RFC 2396bis
- ASSERT_TRUE(testGoodUri("about:")); // empty opaque part / rel-path allowed by RFC 2396bis
-
- // the following test cases are from a Perl script by David A. Wheeler
- // at http://www.dwheeler.com/secure-programs/url.pl
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/"));
- ASSERT_TRUE(testGoodUri("http://1.2.3.4/"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff/"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%20world/"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi+wan&status=jedi"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?onery"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com#bottom"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#bottom"));
- ASSERT_TRUE(testGoodUri("https://www.yahoo.com/"));
- ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/"));
- ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/hello"));
- ASSERT_TRUE(testGoodUri("demo.txt"));
- ASSERT_TRUE(testGoodUri("demo/hello.txt"));
- ASSERT_TRUE(testGoodUri("demo/hello.txt?query=hello#fragment"));
- ASSERT_TRUE(testGoodUri("/cgi-bin/query?query=hello#fragment"));
- ASSERT_TRUE(testGoodUri("/demo.txt"));
- ASSERT_TRUE(testGoodUri("/hello/demo.txt"));
- ASSERT_TRUE(testGoodUri("hello/demo.txt"));
- ASSERT_TRUE(testGoodUri("/"));
- ASSERT_TRUE(testGoodUri(""));
- ASSERT_TRUE(testGoodUri("#"));
- ASSERT_TRUE(testGoodUri("#here"));
-
- // Wheeler's script says these are invalid, but they aren't
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=%00%01"));
- ASSERT_TRUE(testGoodUri("http://www.yaho%6f.com"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%00world/"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello+world/"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&"));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&type="));
- ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#"));
- ASSERT_TRUE(testGoodUri("//"));
-
- // the following test cases are from a Haskell program by Graham Klyne
- // at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
- ASSERT_TRUE(testGoodUri("http://example.org/aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("mailto:local@domain.org"));
- ASSERT_TRUE(testGoodUri("mailto:local@domain.org#frag"));
- ASSERT_TRUE(testGoodUri("HTTP://EXAMPLE.ORG/AAA/BBB#CCC"));
- ASSERT_TRUE(testGoodUri("//example.org/aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("/aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("bbb#ccc"));
- ASSERT_TRUE(testGoodUri("#ccc"));
- ASSERT_TRUE(testGoodUri("#"));
- ASSERT_TRUE(testGoodUri("A'C"));
-
- // escapes
- ASSERT_TRUE(testGoodUri("http://example.org/aaa%2fbbb#ccc"));
- ASSERT_TRUE(testGoodUri("http://example.org/aaa%2Fbbb#ccc"));
- ASSERT_TRUE(testGoodUri("%2F"));
- ASSERT_TRUE(testGoodUri("aaa%2Fbbb"));
-
- // ports
- ASSERT_TRUE(testGoodUri("http://example.org:80/aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("http://example.org:/aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("http://example.org./aaa/bbb#ccc"));
- ASSERT_TRUE(testGoodUri("http://example.123./aaa/bbb#ccc"));
-
- // bare authority
- ASSERT_TRUE(testGoodUri("http://example.org"));
-
- // IPv6 literals (from RFC2732):
- ASSERT_TRUE(testGoodUri("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"));
- ASSERT_TRUE(testGoodUri("http://[1080:0:0:0:8:800:200C:417A]/index.html"));
- ASSERT_TRUE(testGoodUri("http://[3ffe:2a00:100:7031::1]"));
- ASSERT_TRUE(testGoodUri("http://[1080::8:800:200C:417A]/foo"));
- ASSERT_TRUE(testGoodUri("http://[::192.9.5.5]/ipng"));
- ASSERT_TRUE(testGoodUri("http://[::FFFF:129.144.52.38]:80/index.html"));
- ASSERT_TRUE(testGoodUri("http://[2010:836B:4179::836B:4179]"));
- ASSERT_TRUE(testGoodUri("//[2010:836B:4179::836B:4179]"));
-
- // Random other things that crop up
- ASSERT_TRUE(testGoodUri("http://example/Andr&#567;"));
- ASSERT_TRUE(testGoodUri("file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/"));
-}
-
-
-
-TEST(FourSuite, BadUriReferences) {
- ASSERT_TRUE(testBadUri("beepbeep\x07\x07", 8));
- ASSERT_TRUE(testBadUri("\n", 0));
- ASSERT_TRUE(testBadUri("::", 0)); // not OK, per Roy Fielding on the W3C uri list on 2004-04-01
-
- // the following test cases are from a Perl script by David A. Wheeler
- // at http://www.dwheeler.com/secure-programs/url.pl
- ASSERT_TRUE(testBadUri("http://www yahoo.com", 10));
- ASSERT_TRUE(testBadUri("http://www.yahoo.com/hello world/", 26));
- ASSERT_TRUE(testBadUri("http://www.yahoo.com/yelp.html#\"", 31));
-
- // the following test cases are from a Haskell program by Graham Klyne
- // at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
- ASSERT_TRUE(testBadUri("[2010:836B:4179::836B:4179]", 0));
- ASSERT_TRUE(testBadUri(" ", 0));
- ASSERT_TRUE(testBadUri("%", 1));
- ASSERT_TRUE(testBadUri("A%Z", 2));
- ASSERT_TRUE(testBadUri("%ZZ", 1));
- ASSERT_TRUE(testBadUri("%AZ", 2));
- ASSERT_TRUE(testBadUri("A C", 1));
- ASSERT_TRUE(testBadUri("A\\'C", 1)); // r"A\'C"
- ASSERT_TRUE(testBadUri("A`C", 1));
- ASSERT_TRUE(testBadUri("A<C", 1));
- ASSERT_TRUE(testBadUri("A>C", 1));
- ASSERT_TRUE(testBadUri("A^C", 1));
- ASSERT_TRUE(testBadUri("A\\\\C", 1)); // r'A\\C'
- ASSERT_TRUE(testBadUri("A{C", 1));
- ASSERT_TRUE(testBadUri("A|C", 1));
- ASSERT_TRUE(testBadUri("A}C", 1));
- ASSERT_TRUE(testBadUri("A[C", 1));
- ASSERT_TRUE(testBadUri("A]C", 1));
- ASSERT_TRUE(testBadUri("A[**]C", 1));
- ASSERT_TRUE(testBadUri("http://[xyz]/", 8));
- ASSERT_TRUE(testBadUri("http://]/", 7));
- ASSERT_TRUE(testBadUri("http://example.org/[2010:836B:4179::836B:4179]", 19));
- ASSERT_TRUE(testBadUri("http://example.org/abc#[2010:836B:4179::836B:4179]", 23));
- ASSERT_TRUE(testBadUri("http://example.org/xxx/[qwerty]#a[b]", 23));
-
- // from a post to the W3C uri list on 2004-02-17
- // breaks at 22 instead of 17 because everything up to that point is a valid userinfo
- ASSERT_TRUE(testBadUri("http://w3c.org:80path1/path2", 22));
-}
-
-
-
-namespace {
-
-bool normalizeAndCompare(const char * uriText,
- const char * expectedNormalized) {
- UriParserStateA stateA;
- int res;
-
- UriUriA testUri;
- stateA.uri = &testUri;
- res = uriParseUriA(&stateA, uriText);
- if (res != 0) {
- uriFreeUriMembersA(&testUri);
- return false;
- }
-
- // Expected result
- UriUriA expectedUri;
- stateA.uri = &expectedUri;
- res = uriParseUriA(&stateA, expectedNormalized);
- if (res != 0) {
- uriFreeUriMembersA(&testUri);
- uriFreeUriMembersA(&expectedUri);
- return false;
- }
-
- res = uriNormalizeSyntaxA(&testUri);
- if (res != 0) {
- uriFreeUriMembersA(&testUri);
- uriFreeUriMembersA(&expectedUri);
- return false;
- }
-
- const bool equalAfter = (URI_TRUE == uriEqualsUriA(&testUri, &expectedUri));
- uriFreeUriMembersA(&testUri);
- uriFreeUriMembersA(&expectedUri);
- return equalAfter;
-}
-
-} // namespace
-
-
-
-TEST(FourSuite, CaseNormalizationTests) {
- ASSERT_TRUE(normalizeAndCompare("HTTP://www.EXAMPLE.com/", "http://www.example.com/"));
- ASSERT_TRUE(normalizeAndCompare("example://A/b/c/%7bfoo%7d", "example://a/b/c/%7Bfoo%7D"));
-}
-
-
-
-TEST(FourSuite, PctEncNormalizationTests) {
- ASSERT_TRUE(normalizeAndCompare("http://host/%7Euser/x/y/z", "http://host/~user/x/y/z"));
- ASSERT_TRUE(normalizeAndCompare("http://host/%7euser/x/y/z", "http://host/~user/x/y/z"));
-}
-
-
-
-TEST(FourSuite, PathSegmentNormalizationTests) {
- ASSERT_TRUE(normalizeAndCompare("/a/b/../../c", "/c"));
- // ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "a/b/../../c"));
- // Fixed:
- ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "c"));
- ASSERT_TRUE(normalizeAndCompare("/a/b/././c", "/a/b/c"));
- // ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/././c"));
- // Fixed:
- ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/c"));
- ASSERT_TRUE(normalizeAndCompare("/a/b/../c/././d", "/a/c/d"));
- // ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/b/../c/././d"));
- // Fixed:
- ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/c/d"));
-}
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <gtest/gtest.h>
+
+#include <uriparser/Uri.h>
+
+
+
+// All testcases in this file are coming from
+// http://cvs.4suite.org/viewcvs/4Suite/test/Lib/test_uri.py
+
+
+namespace {
+
+bool testAddOrRemoveBaseHelper(const char * ref, const char * base,
+ const char * expected, bool add = true, bool domainRootMode = false) {
+ UriParserStateA stateA;
+
+ // Base
+ UriUriA baseUri;
+ stateA.uri = &baseUri;
+ int res = uriParseUriA(&stateA, base);
+ if (res != 0) {
+ return false;
+ }
+
+ // Rel
+ UriUriA relUri;
+ stateA.uri = &relUri;
+ res = uriParseUriA(&stateA, ref);
+ if (res != 0) {
+ uriFreeUriMembersA(&baseUri);
+ return false;
+ }
+
+ // Expected result
+ UriUriA expectedUri;
+ stateA.uri = &expectedUri;
+ res = uriParseUriA(&stateA, expected);
+ if (res != 0) {
+ uriFreeUriMembersA(&baseUri);
+ uriFreeUriMembersA(&relUri);
+ uriFreeUriMembersA(&expectedUri);
+ return false;
+ }
+
+ // Transform
+ UriUriA transformedUri;
+ if (add) {
+ res = uriAddBaseUriA(&transformedUri, &relUri, &baseUri);
+ } else {
+ res = uriRemoveBaseUriA(&transformedUri, &relUri, &baseUri,
+ domainRootMode ? URI_TRUE : URI_FALSE);
+ }
+ if (res != 0) {
+ uriFreeUriMembersA(&baseUri);
+ uriFreeUriMembersA(&relUri);
+ uriFreeUriMembersA(&expectedUri);
+ uriFreeUriMembersA(&transformedUri);
+ return false;
+ }
+
+ const bool equal = (URI_TRUE == uriEqualsUriA(&transformedUri, &expectedUri));
+ if (!equal) {
+ char transformedUriText[1024 * 8];
+ char expectedUriText[1024 * 8];
+ uriToStringA(transformedUriText, &transformedUri, 1024 * 8, NULL);
+ uriToStringA(expectedUriText, &expectedUri, 1024 * 8, NULL);
+ printf("\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
+ }
+
+ uriFreeUriMembersA(&baseUri);
+ uriFreeUriMembersA(&relUri);
+ uriFreeUriMembersA(&expectedUri);
+ uriFreeUriMembersA(&transformedUri);
+ return equal;
+}
+
+} // namespace
+
+
+TEST(FourSuite, AbsolutizeTestCases) {
+ const char * const BASE_URI[] = {
+ "http://a/b/c/d;p?q",
+ "http://a/b/c/d;p?q=1/2",
+ "http://a/b/c/d;p=1/2?q",
+ "fred:///s//a/b/c",
+ "http:///s//a/b/c"};
+
+ // ref, base, exptected
+
+ // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../c", "foo:a/b", "foo:c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo:.", "foo:a", "foo:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../../../bar", "zz:abc", "zz:/bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../bar", "zz:abc", "zz:/bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../../../bar", "zz:abc", "zz:bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../bar", "zz:abc", "zz:bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("zz:.", "zz:abc", "zz:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/.", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/.foo", BASE_URI[0], "http://a/.foo"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".foo", BASE_URI[0], "http://a/b/c/.foo"));
+
+ // http://gbiv.com/protocols/uri/test/rel_examples1.html
+ // examples from RFC 2396
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[0], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[0], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[0], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[0], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[0], "http://g"));
+
+ // changed with RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[0], "http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[0], "http://a/b/c/g?y"));
+
+ // changed with RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("#s", BASE_URI[0], "http://a/b/c/d;p?q#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[0], "http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y#s", BASE_URI[0], "http://a/b/c/g?y#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[0], "http://a/b/c/;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[0], "http://a/b/c/g;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x?y#s", BASE_URI[0], "http://a/b/c/g;x?y#s"));
+
+ // changed with RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", BASE_URI[0], "http://a/b/c/d;p?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".", BASE_URI[0], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[0], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..", BASE_URI[0], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[0], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[0], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../..", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[0], "http://a/g")); // http://a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[0], "http://a/g")); // http://a/../../g
+
+ // changed with RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/./g", BASE_URI[0], "http://a/g"));
+
+ // changed with RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/../g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g.", BASE_URI[0], "http://a/b/c/g."));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".g", BASE_URI[0], "http://a/b/c/.g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g..", BASE_URI[0], "http://a/b/c/g.."));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..g", BASE_URI[0], "http://a/b/c/..g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./../g", BASE_URI[0], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g/.", BASE_URI[0], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/./h", BASE_URI[0], "http://a/b/c/g/h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/../h", BASE_URI[0], "http://a/b/c/h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[0], "http://a/b/c/g;x=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[0], "http://a/b/c/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[0], "http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[0], "http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[0], "http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[0], "http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:g", BASE_URI[0], "http:g")); // http://a/b/c/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:", BASE_URI[0], "http:")); // BASE_URI[0]
+
+ // not sure where this one originated
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/a/b/c/./../../g", BASE_URI[0], "http://a/a/g"));
+
+ // http://gbiv.com/protocols/uri/test/rel_examples2.html
+ // slashes in base URI's query args
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[1], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[1], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[1], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[1], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[1], "http://g"));
+
+ // changed in RFC 2396bis
+ // ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[1], "http://a/b/c/g?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[1], "http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[1], "http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[1], "http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[1], "http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[1], "http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[1], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[1], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[1], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[1], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[1], "http://a/g"));
+
+ // http://gbiv.com/protocols/uri/test/rel_examples3.html
+ // slashes in path params
+ // all of these changed in RFC 2396bis
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[2], "http://a/b/c/d;p=1/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[2], "http://a/b/c/d;p=1/g?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[2], "http://a/b/c/d;p=1/;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[2], "http://a/b/c/d;p=1/g;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[2], "http://a/b/c/d;p=1/g;x=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[2], "http://a/b/c/d;p=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[2], "http://a/b/c/d;p=1/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[2], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[2], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[2], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[2], "http://a/b/g"));
+
+ // http://gbiv.com/protocols/uri/test/rel_examples4.html
+ // double and triple slash, unknown scheme
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[3], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[3], "fred:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[3], "fred:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[3], "fred:///s//a/b/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[3], "fred://g")); // may change to fred:///s//g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[3], "fred://g/x")); // may change to fred:///s//g/x
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[3], "fred:///g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[3], "fred:///s//a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[3], "fred:///s//a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[3], "fred:///s//a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[3], "fred:///s//")); // may change to fred:///s//a/../
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[3], "fred:///s//g")); // may change to fred:///s//a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[3], "fred:///s/g")); // may change to fred:///s//a/../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/../../../g
+
+ // http://gbiv.com/protocols/uri/test/rel_examples5.html
+ // double and triple slash, well-known scheme
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[4], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[4], "http:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[4], "http:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[4], "http:///s//a/b/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[4], "http:///g")); // may change to http:///s//a/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[4], "http://g")); // may change to http:///s//g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[4], "http://g/x")); // may change to http:///s//g/x
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[4], "http:///g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[4], "http:///s//a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[4], "http:///s//a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[4], "http:///s//a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[4], "http:///s//")); // may change to http:///s//a/../
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[4], "http:///s//g")); // may change to http:///s//a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[4], "http:///s/g")); // may change to http:///s//a/../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[4], "http:///g")); // may change to http:///s//a/../../../g
+
+ // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("bar:abc", "foo:xyz", "bar:abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "http://example/x/y/z", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/x/abc", "http://example2/x/y/z", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "http://ex/x/y/z", "http://ex/x/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "http://ex/x/y", "http://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "http://ex/x/y", "http://ex/x/q/r#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "http://ex/x/y", "http://ex/x/q/r#s/t"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "http://ex/x/y", "ftp://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y", "http://ex/x/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/", "http://ex/x/y/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/pdq", "http://ex/x/y/pdq"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "http://ex/x/y/", "http://ex/x/y/z/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("#Animal", "file:/swap/test/animal.rdf", "file:/swap/test/animal.rdf#Animal"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "file:/e/x/y/z", "file:/e/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/example/x/abc", "file:/example2/x/y/z", "file:/example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "file:/ex/x/y/z", "file:/ex/x/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/r", "file:/ex/x/y/z", "file:/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "file:/ex/x/y", "file:/ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "file:/ex/x/y", "file:/ex/x/q/r#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#", "file:/ex/x/y", "file:/ex/x/q/r#"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "file:/ex/x/y", "file:/ex/x/q/r#s/t"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "file:/ex/x/y", "ftp://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y", "file:/ex/x/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/", "file:/ex/x/y/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/pdq", "file:/ex/x/y/pdq"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "file:/ex/x/y/", "file:/ex/x/y/z/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/devel/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./#blort", "file:/some/dir/foo", "file:/some/dir/#blort"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./#", "file:/some/dir/foo", "file:/some/dir/#"));
+
+ // Ryan Lee
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", "http://example/x/abc.efg", "http://example/x/"));
+
+ // Graham Klyne's tests
+ // http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls
+ // 01-31 are from Connelly's cases
+
+ // 32-49
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./q:r", "http://ex/x/y", "http://ex/x/q:r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./p=q:r", "http://ex/x/y", "http://ex/x/p=q:r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?pp/rr", "http://ex/x/y?pp/qq", "http://ex/x/y?pp/rr"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("y/z", "http://ex/x/y?pp/qq", "http://ex/x/y/z"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local/qual@domain.org#frag", "mailto:local", "mailto:local/qual@domain.org#frag"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("more/qual2@domain2.org#frag", "mailto:local/qual1@domain1.org", "mailto:local/more/qual2@domain2.org#frag"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("y?q", "http://ex/x/y?q", "http://ex/x/y?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x/y?q", "http://ex?p", "http://ex/x/y?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("c/d", "foo:a/b", "foo:a/c/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/c/d", "foo:a/b", "foo:/c/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "foo:a/b?c#d", "foo:a/b?c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c", "foo:a", "foo:b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:/a/y/z", "foo:/a/b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./b/c", "foo:a", "foo:b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/./b/c", "foo:a", "foo:/b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../d", "foo://a//b/c", "foo://a/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".", "foo:a", "foo:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..", "foo:a", "foo:"));
+
+ // 50-57 (cf. TimBL comments --
+ // http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,
+ // http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x/y%2Fz", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../x%2Fabc", "http://example/a/x/y/z", "http://example/a/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../x%2Fabc", "http://example/a/x/y%2Fz", "http://example/a/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x%2Fy/z", "http://example/x%2Fy/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q%3Ar", "http://ex/x/y", "http://ex/x/q%3Ar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y/z", "http://example/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
+
+ // 70-77
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2", "mailto:local1@domain1?query1", "mailto:local2@domain2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1", "mailto:local2@domain2?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1?query1", "mailto:local2@domain2?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local@domain?query2", "mailto:?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b?c/../d", "foo:bar", "http://example/a/b?c/../d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b#c/../d", "foo:bar", "http://example/a/b#c/../d"));
+
+ // 82-88
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http://example.org/base/uri", "http:this"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http:base", "http:this"));
+ // Whole in the URI spec, see http://lists.w3.org/Archives/Public/uri/2007Aug/0003.html
+ // ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f://g")); // ORIGINAL
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f:/.//g")); // FIXED ONE
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c//d/e", "f://example.org/base/a", "f://example.org/base/b/c//d/e"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("m2@example.ord/c2@example.org", "mid:m@example.ord/c@example.org", "mid:m@example.ord/m2@example.ord/c2@example.org"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("mini1.xml", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:a/y/z", "foo:a/b/c"));
+}
+
+
+
+TEST(FourSuite, RelativizeTestCases) {
+ const bool REMOVE_MODE = false;
+ const bool DOMAIN_ROOT_MODE = true;
+
+ // to convert, base, exptected
+
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d", "b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/b/c", "s://ex/a/d", "/b/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/b/", "c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://other.ex/a/b/", "s://ex/a/d", "//other.ex/a/b/", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://other.ex/a/d", "//ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("t://ex/a/b/c", "s://ex/a/d", "t://ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "t://ex/a/d", "s://ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a", "s://ex/b/c/d", "/a", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/c/d", "s://ex/a", "b/c/d", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h", "s://ex/a/d?w", "b/c?h", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c#h", "s://ex/a/d#w", "b/c#h", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h#i", "s://ex/a/d?w#j", "b/c?h#i", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a#i", "s://ex/a", "#i", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a?i", "s://ex/a", "?i", REMOVE_MODE));
+
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/b/", "", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a/b", "", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/", "s://ex/", "", REMOVE_MODE));
+
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d/c", "../b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/", "s://ex/a/d/c", "../b/c/", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/d", "s://ex/a/d/c/d", "../../b/c/d", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/d/e/f", "/a/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/c/d/e", "../../b/", REMOVE_MODE));
+
+ // Some tests to ensure that empty path segments don't cause problems.
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a//b/c", "../../b", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a///b", "s://ex/a/", ".///b", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/", "s://ex/a///b", "../../", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a//b/c", "s://ex/a/b", ".//b/c", REMOVE_MODE));
+}
+
+
+namespace {
+
+int testParseUri(const char * uriText, const char ** expectedErrorPos = NULL) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+ int res = uriParseUriA(&state, uriText);
+ if (expectedErrorPos != NULL) {
+ *expectedErrorPos = state.errorPos;
+ }
+ uriFreeUriMembersA(&uri);
+ return res;
+}
+
+
+
+bool testGoodUri(const char * uriText) {
+ return (testParseUri(uriText) == 0);
+}
+
+
+
+bool testBadUri(const char * uriText, int expectedErrorOffset = -1) {
+ const char * errorPos = NULL;
+ const int ret = testParseUri(uriText, &errorPos);
+ return ((ret == URI_ERROR_SYNTAX)
+ && (errorPos != NULL)
+ && (
+ (expectedErrorOffset == -1)
+ || (errorPos == (uriText + expectedErrorOffset))
+ ));
+}
+
+} // namespace
+
+
+
+TEST(FourSuite, GoodUriReferences) {
+ ASSERT_TRUE(testGoodUri("file:///foo/bar"));
+ ASSERT_TRUE(testGoodUri("mailto:user@host?subject=blah"));
+ ASSERT_TRUE(testGoodUri("dav:")); // empty opaque part / rel-path allowed by RFC 2396bis
+ ASSERT_TRUE(testGoodUri("about:")); // empty opaque part / rel-path allowed by RFC 2396bis
+
+ // the following test cases are from a Perl script by David A. Wheeler
+ // at http://www.dwheeler.com/secure-programs/url.pl
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("http://1.2.3.4/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%20world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi+wan&status=jedi"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?onery"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com#bottom"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#bottom"));
+ ASSERT_TRUE(testGoodUri("https://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/hello"));
+ ASSERT_TRUE(testGoodUri("demo.txt"));
+ ASSERT_TRUE(testGoodUri("demo/hello.txt"));
+ ASSERT_TRUE(testGoodUri("demo/hello.txt?query=hello#fragment"));
+ ASSERT_TRUE(testGoodUri("/cgi-bin/query?query=hello#fragment"));
+ ASSERT_TRUE(testGoodUri("/demo.txt"));
+ ASSERT_TRUE(testGoodUri("/hello/demo.txt"));
+ ASSERT_TRUE(testGoodUri("hello/demo.txt"));
+ ASSERT_TRUE(testGoodUri("/"));
+ ASSERT_TRUE(testGoodUri(""));
+ ASSERT_TRUE(testGoodUri("#"));
+ ASSERT_TRUE(testGoodUri("#here"));
+
+ // Wheeler's script says these are invalid, but they aren't
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=%00%01"));
+ ASSERT_TRUE(testGoodUri("http://www.yaho%6f.com"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%00world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello+world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&type="));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#"));
+ ASSERT_TRUE(testGoodUri("//"));
+
+ // the following test cases are from a Haskell program by Graham Klyne
+ // at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("mailto:local@domain.org"));
+ ASSERT_TRUE(testGoodUri("mailto:local@domain.org#frag"));
+ ASSERT_TRUE(testGoodUri("HTTP://EXAMPLE.ORG/AAA/BBB#CCC"));
+ ASSERT_TRUE(testGoodUri("//example.org/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("#ccc"));
+ ASSERT_TRUE(testGoodUri("#"));
+ ASSERT_TRUE(testGoodUri("A'C"));
+
+ // escapes
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa%2fbbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa%2Fbbb#ccc"));
+ ASSERT_TRUE(testGoodUri("%2F"));
+ ASSERT_TRUE(testGoodUri("aaa%2Fbbb"));
+
+ // ports
+ ASSERT_TRUE(testGoodUri("http://example.org:80/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org:/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org./aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.123./aaa/bbb#ccc"));
+
+ // bare authority
+ ASSERT_TRUE(testGoodUri("http://example.org"));
+
+ // IPv6 literals (from RFC2732):
+ ASSERT_TRUE(testGoodUri("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[1080:0:0:0:8:800:200C:417A]/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[3ffe:2a00:100:7031::1]"));
+ ASSERT_TRUE(testGoodUri("http://[1080::8:800:200C:417A]/foo"));
+ ASSERT_TRUE(testGoodUri("http://[::192.9.5.5]/ipng"));
+ ASSERT_TRUE(testGoodUri("http://[::FFFF:129.144.52.38]:80/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[2010:836B:4179::836B:4179]"));
+ ASSERT_TRUE(testGoodUri("//[2010:836B:4179::836B:4179]"));
+
+ // Random other things that crop up
+ ASSERT_TRUE(testGoodUri("http://example/Andr&#567;"));
+ ASSERT_TRUE(testGoodUri("file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/"));
+}
+
+
+
+TEST(FourSuite, BadUriReferences) {
+ ASSERT_TRUE(testBadUri("beepbeep\x07\x07", 8));
+ ASSERT_TRUE(testBadUri("\n", 0));
+ ASSERT_TRUE(testBadUri("::", 0)); // not OK, per Roy Fielding on the W3C uri list on 2004-04-01
+
+ // the following test cases are from a Perl script by David A. Wheeler
+ // at http://www.dwheeler.com/secure-programs/url.pl
+ ASSERT_TRUE(testBadUri("http://www yahoo.com", 10));
+ ASSERT_TRUE(testBadUri("http://www.yahoo.com/hello world/", 26));
+ ASSERT_TRUE(testBadUri("http://www.yahoo.com/yelp.html#\"", 31));
+
+ // the following test cases are from a Haskell program by Graham Klyne
+ // at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
+ ASSERT_TRUE(testBadUri("[2010:836B:4179::836B:4179]", 0));
+ ASSERT_TRUE(testBadUri(" ", 0));
+ ASSERT_TRUE(testBadUri("%", 1));
+ ASSERT_TRUE(testBadUri("A%Z", 2));
+ ASSERT_TRUE(testBadUri("%ZZ", 1));
+ ASSERT_TRUE(testBadUri("%AZ", 2));
+ ASSERT_TRUE(testBadUri("A C", 1));
+ ASSERT_TRUE(testBadUri("A\\'C", 1)); // r"A\'C"
+ ASSERT_TRUE(testBadUri("A`C", 1));
+ ASSERT_TRUE(testBadUri("A<C", 1));
+ ASSERT_TRUE(testBadUri("A>C", 1));
+ ASSERT_TRUE(testBadUri("A^C", 1));
+ ASSERT_TRUE(testBadUri("A\\\\C", 1)); // r'A\\C'
+ ASSERT_TRUE(testBadUri("A{C", 1));
+ ASSERT_TRUE(testBadUri("A|C", 1));
+ ASSERT_TRUE(testBadUri("A}C", 1));
+ ASSERT_TRUE(testBadUri("A[C", 1));
+ ASSERT_TRUE(testBadUri("A]C", 1));
+ ASSERT_TRUE(testBadUri("A[**]C", 1));
+ ASSERT_TRUE(testBadUri("http://[xyz]/", 8));
+ ASSERT_TRUE(testBadUri("http://]/", 7));
+ ASSERT_TRUE(testBadUri("http://example.org/[2010:836B:4179::836B:4179]", 19));
+ ASSERT_TRUE(testBadUri("http://example.org/abc#[2010:836B:4179::836B:4179]", 23));
+ ASSERT_TRUE(testBadUri("http://example.org/xxx/[qwerty]#a[b]", 23));
+
+ // from a post to the W3C uri list on 2004-02-17
+ // breaks at 22 instead of 17 because everything up to that point is a valid userinfo
+ ASSERT_TRUE(testBadUri("http://w3c.org:80path1/path2", 22));
+}
+
+
+
+namespace {
+
+bool normalizeAndCompare(const char * uriText,
+ const char * expectedNormalized) {
+ UriParserStateA stateA;
+ int res;
+
+ UriUriA testUri;
+ stateA.uri = &testUri;
+ res = uriParseUriA(&stateA, uriText);
+ if (res != 0) {
+ uriFreeUriMembersA(&testUri);
+ return false;
+ }
+
+ // Expected result
+ UriUriA expectedUri;
+ stateA.uri = &expectedUri;
+ res = uriParseUriA(&stateA, expectedNormalized);
+ if (res != 0) {
+ uriFreeUriMembersA(&testUri);
+ uriFreeUriMembersA(&expectedUri);
+ return false;
+ }
+
+ res = uriNormalizeSyntaxA(&testUri);
+ if (res != 0) {
+ uriFreeUriMembersA(&testUri);
+ uriFreeUriMembersA(&expectedUri);
+ return false;
+ }
+
+ const bool equalAfter = (URI_TRUE == uriEqualsUriA(&testUri, &expectedUri));
+ uriFreeUriMembersA(&testUri);
+ uriFreeUriMembersA(&expectedUri);
+ return equalAfter;
+}
+
+} // namespace
+
+
+
+TEST(FourSuite, CaseNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("HTTP://www.EXAMPLE.com/", "http://www.example.com/"));
+ ASSERT_TRUE(normalizeAndCompare("example://A/b/c/%7bfoo%7d", "example://a/b/c/%7Bfoo%7D"));
+}
+
+
+
+TEST(FourSuite, PctEncNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("http://host/%7Euser/x/y/z", "http://host/~user/x/y/z"));
+ ASSERT_TRUE(normalizeAndCompare("http://host/%7euser/x/y/z", "http://host/~user/x/y/z"));
+}
+
+
+
+TEST(FourSuite, PathSegmentNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("/a/b/../../c", "/c"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "a/b/../../c"));
+ // Fixed:
+ ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "c"));
+ ASSERT_TRUE(normalizeAndCompare("/a/b/././c", "/a/b/c"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/././c"));
+ // Fixed:
+ ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/c"));
+ ASSERT_TRUE(normalizeAndCompare("/a/b/../c/././d", "/a/c/d"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/b/../c/././d"));
+ // Fixed:
+ ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/c/d"));
+}
diff --git a/contrib/restricted/uriparser/test/MemoryManagerSuite.cpp b/contrib/restricted/uriparser/test/MemoryManagerSuite.cpp
index 6b684167b7..0abc263bca 100644
--- a/contrib/restricted/uriparser/test/MemoryManagerSuite.cpp
+++ b/contrib/restricted/uriparser/test/MemoryManagerSuite.cpp
@@ -1,41 +1,41 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
- * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#undef NDEBUG // because we rely on assert(3) further down
-
-#include <cassert>
-#include <cerrno>
-#include <cstring> // memcpy
-#include <gtest/gtest.h>
-
-#include <uriparser/Uri.h>
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#undef NDEBUG // because we rely on assert(3) further down
+
+#include <cassert>
+#include <cerrno>
+#include <cstring> // memcpy
+#include <gtest/gtest.h>
+
+#include <uriparser/Uri.h>
// For defaultMemoryManager
extern "C" {
-#include "../src/UriMemory.h"
+#include "../src/UriMemory.h"
}
-
-
-namespace {
-
+
+
+namespace {
+
static void * failingMalloc(UriMemoryManager * memory, size_t size);
@@ -50,9 +50,9 @@ class FailingMemoryManager {
private:
UriMemoryManager memoryManager;
unsigned int callCountAlloc;
- unsigned int callCountFree;
+ unsigned int callCountFree;
unsigned int failAllocAfterTimes;
-
+
friend void * failingMalloc(UriMemoryManager * memory, size_t size);
friend void * failingCalloc(UriMemoryManager * memory, size_t nmemb, size_t size);
friend void * failingRealloc(UriMemoryManager * memory, void * ptr, size_t size);
@@ -69,7 +69,7 @@ public:
this->memoryManager.reallocarray = failingReallocarray;
this->memoryManager.free = countingFree;
this->memoryManager.userData = this;
- }
+ }
UriMemoryManager * operator&() {
return &(this->memoryManager);
@@ -78,10 +78,10 @@ public:
unsigned int getCallCountFree() const {
return this->callCountFree;
}
-};
-
-
-
+};
+
+
+
static void * failingMalloc(UriMemoryManager * memory, size_t size) {
FailingMemoryManager * const fmm = static_cast<FailingMemoryManager *>(memory->userData);
fmm->callCountAlloc++;
@@ -90,10 +90,10 @@ static void * failingMalloc(UriMemoryManager * memory, size_t size) {
return NULL;
}
return malloc(size);
-}
-
-
-
+}
+
+
+
static void * failingCalloc(UriMemoryManager * memory, size_t nmemb, size_t size) {
FailingMemoryManager * const fmm = static_cast<FailingMemoryManager *>(memory->userData);
fmm->callCountAlloc++;
@@ -102,10 +102,10 @@ static void * failingCalloc(UriMemoryManager * memory, size_t nmemb, size_t size
return NULL;
}
return calloc(nmemb, size);
-}
-
-
-
+}
+
+
+
static void * failingRealloc(UriMemoryManager * memory, void * ptr, size_t size) {
FailingMemoryManager * const fmm = static_cast<FailingMemoryManager *>(memory->userData);
fmm->callCountAlloc++;
@@ -114,253 +114,253 @@ static void * failingRealloc(UriMemoryManager * memory, void * ptr, size_t size)
return NULL;
}
return realloc(ptr, size);
-}
-
-
-
+}
+
+
+
static void * failingReallocarray(UriMemoryManager * memory, void * ptr, size_t nmemb, size_t size) {
return uriEmulateReallocarray(memory, ptr, nmemb, size);
-}
-
-
-
-static void countingFree(UriMemoryManager * memory, void * ptr) {
+}
+
+
+
+static void countingFree(UriMemoryManager * memory, void * ptr) {
FailingMemoryManager * const fmm = static_cast<FailingMemoryManager *>(memory->userData);
fmm->callCountFree++;
return free(ptr);
-}
-
-
-
-static UriUriA parse(const char * sourceUriString) {
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
- assert(uriParseUriA(&state, sourceUriString) == URI_SUCCESS);
- return uri;
-}
-
-
-
-static UriQueryListA * parseQueryList(const char * queryString) {
- UriQueryListA * queryList;
- const char * const first = queryString;
- const char * const afterLast = first + strlen(first);
- assert(uriDissectQueryMallocA(&queryList, NULL, first, afterLast)
- == URI_SUCCESS);
- return queryList;
-}
-
-} // namespace
-
-
-
-TEST(MemoryManagerCompletenessSuite, AllFunctionMembersRequired) {
- UriUriA uri = parse("whatever");
- UriMemoryManager memory;
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- memory.malloc = NULL;
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- memory.calloc = NULL;
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- memory.realloc = NULL;
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- memory.reallocarray = NULL;
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- memory.free = NULL;
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
- ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory), URI_SUCCESS);
-}
-
-
-
-TEST(MemoryManagerCompletenessSuite, MallocAndFreeRequiredOnly) {
- UriMemoryManager memory;
- UriMemoryManager backend;
-
- memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
- backend.malloc = NULL;
- ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-
- memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
- backend.free = NULL;
- ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
- URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
-}
-
-
-
+}
+
+
+
+static UriUriA parse(const char * sourceUriString) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+ assert(uriParseUriA(&state, sourceUriString) == URI_SUCCESS);
+ return uri;
+}
+
+
+
+static UriQueryListA * parseQueryList(const char * queryString) {
+ UriQueryListA * queryList;
+ const char * const first = queryString;
+ const char * const afterLast = first + strlen(first);
+ assert(uriDissectQueryMallocA(&queryList, NULL, first, afterLast)
+ == URI_SUCCESS);
+ return queryList;
+}
+
+} // namespace
+
+
+
+TEST(MemoryManagerCompletenessSuite, AllFunctionMembersRequired) {
+ UriUriA uri = parse("whatever");
+ UriMemoryManager memory;
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.malloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.calloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.realloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.reallocarray = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.free = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory), URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerCompletenessSuite, MallocAndFreeRequiredOnly) {
+ UriMemoryManager memory;
+ UriMemoryManager backend;
+
+ memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
+ backend.malloc = NULL;
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
+ backend.free = NULL;
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+}
+
+
+
TEST(MemoryManagerTestingSuite, DISABLED_DefaultMemoryManager) {
- ASSERT_EQ(uriTestMemoryManager(&defaultMemoryManager), URI_SUCCESS);
-}
-
-
-
-TEST(MemoryManagerTestingSuite, CompleteMemoryManager) {
- UriMemoryManager memory;
- UriMemoryManager backend;
-
- memset(&backend, 0, sizeof(UriMemoryManager));
- backend.malloc = defaultMemoryManager.malloc;
- backend.free = defaultMemoryManager.free;
-
- ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
- URI_SUCCESS);
-
- ASSERT_EQ(uriTestMemoryManager(&memory), URI_SUCCESS);
-}
-
-
-
+ ASSERT_EQ(uriTestMemoryManager(&defaultMemoryManager), URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, CompleteMemoryManager) {
+ UriMemoryManager memory;
+ UriMemoryManager backend;
+
+ memset(&backend, 0, sizeof(UriMemoryManager));
+ backend.malloc = defaultMemoryManager.malloc;
+ backend.free = defaultMemoryManager.free;
+
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_SUCCESS);
+
+ ASSERT_EQ(uriTestMemoryManager(&memory), URI_SUCCESS);
+}
+
+
+
TEST(MemoryManagerTestingSuite, DISABLED_EmulateCalloc) {
- UriMemoryManager partialEmulationMemoryManager;
- memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
- sizeof(UriMemoryManager));
- partialEmulationMemoryManager.calloc = uriEmulateCalloc;
-
- ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
- URI_SUCCESS);
-}
-
-
-
-TEST(MemoryManagerTestingSuite, EmulateReallocarray) {
- UriMemoryManager partialEmulationMemoryManager;
- memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
- sizeof(UriMemoryManager));
- partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
-
- ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
- URI_SUCCESS);
-}
-
-
-
-TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateCalloc) {
- EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
-
- errno = 0;
- ASSERT_EQ(NULL, uriEmulateCalloc(
- &defaultMemoryManager, (size_t)-1, (size_t)-1));
- ASSERT_EQ(errno, ENOMEM);
-}
-
-
-
-TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateReallocarray) {
- EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
-
- errno = 0;
- ASSERT_EQ(NULL, uriEmulateReallocarray(
- &defaultMemoryManager, NULL, (size_t)-1, (size_t)-1));
- ASSERT_EQ(errno, ENOMEM);
-}
-
-
-
-TEST(MemoryManagerTestingSuite, EmulateCallocAndReallocarray) {
- UriMemoryManager partialEmulationMemoryManager;
- memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
- sizeof(UriMemoryManager));
- partialEmulationMemoryManager.calloc = uriEmulateCalloc;
- partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
-
- ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
- URI_SUCCESS);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, AddBaseUriExMm) {
- UriUriA absoluteDest;
- UriUriA relativeSource = parse("foo");
- UriUriA absoluteBase = parse("http://example.org/bar");
- const UriResolutionOptions options = URI_RESOLVE_STRICTLY;
- FailingMemoryManager failingMemoryManager;
-
- ASSERT_EQ(uriAddBaseUriExMmA(&absoluteDest, &relativeSource,
- &absoluteBase, options, &failingMemoryManager),
- URI_ERROR_MALLOC);
-
- uriFreeUriMembersA(&relativeSource);
- uriFreeUriMembersA(&absoluteBase);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, ComposeQueryMallocExMm) {
- char * dest = NULL;
- UriQueryListA * const queryList = parseQueryList("k1=v1");
- UriBool spaceToPlus = URI_TRUE; // not of interest
- UriBool normalizeBreaks = URI_TRUE; // not of interest
- FailingMemoryManager failingMemoryManager;
-
- ASSERT_EQ(uriComposeQueryMallocExMmA(&dest, queryList,
- spaceToPlus, normalizeBreaks, &failingMemoryManager),
- URI_ERROR_MALLOC);
-
- uriFreeQueryListA(queryList);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, DissectQueryMallocExMm) {
- UriQueryListA * queryList;
- int itemCount;
- const char * const first = "k1=v1&k2=v2";
- const char * const afterLast = first + strlen(first);
- const UriBool plusToSpace = URI_TRUE; // not of interest
- const UriBreakConversion breakConversion = URI_BR_DONT_TOUCH; // not o. i.
- FailingMemoryManager failingMemoryManager;
-
- ASSERT_EQ(uriDissectQueryMallocExMmA(&queryList, &itemCount,
- first, afterLast, plusToSpace, breakConversion,
- &failingMemoryManager),
- URI_ERROR_MALLOC);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, FreeQueryListMm) {
- UriQueryListA * const queryList = parseQueryList("k1=v1");
- FailingMemoryManager failingMemoryManager;
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.calloc = uriEmulateCalloc;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, EmulateReallocarray) {
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateCalloc) {
+ EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
+
+ errno = 0;
+ ASSERT_EQ(NULL, uriEmulateCalloc(
+ &defaultMemoryManager, (size_t)-1, (size_t)-1));
+ ASSERT_EQ(errno, ENOMEM);
+}
+
+
+
+TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateReallocarray) {
+ EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
+
+ errno = 0;
+ ASSERT_EQ(NULL, uriEmulateReallocarray(
+ &defaultMemoryManager, NULL, (size_t)-1, (size_t)-1));
+ ASSERT_EQ(errno, ENOMEM);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, EmulateCallocAndReallocarray) {
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.calloc = uriEmulateCalloc;
+ partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, AddBaseUriExMm) {
+ UriUriA absoluteDest;
+ UriUriA relativeSource = parse("foo");
+ UriUriA absoluteBase = parse("http://example.org/bar");
+ const UriResolutionOptions options = URI_RESOLVE_STRICTLY;
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriAddBaseUriExMmA(&absoluteDest, &relativeSource,
+ &absoluteBase, options, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeUriMembersA(&relativeSource);
+ uriFreeUriMembersA(&absoluteBase);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, ComposeQueryMallocExMm) {
+ char * dest = NULL;
+ UriQueryListA * const queryList = parseQueryList("k1=v1");
+ UriBool spaceToPlus = URI_TRUE; // not of interest
+ UriBool normalizeBreaks = URI_TRUE; // not of interest
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriComposeQueryMallocExMmA(&dest, queryList,
+ spaceToPlus, normalizeBreaks, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeQueryListA(queryList);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, DissectQueryMallocExMm) {
+ UriQueryListA * queryList;
+ int itemCount;
+ const char * const first = "k1=v1&k2=v2";
+ const char * const afterLast = first + strlen(first);
+ const UriBool plusToSpace = URI_TRUE; // not of interest
+ const UriBreakConversion breakConversion = URI_BR_DONT_TOUCH; // not o. i.
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriDissectQueryMallocExMmA(&queryList, &itemCount,
+ first, afterLast, plusToSpace, breakConversion,
+ &failingMemoryManager),
+ URI_ERROR_MALLOC);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, FreeQueryListMm) {
+ UriQueryListA * const queryList = parseQueryList("k1=v1");
+ FailingMemoryManager failingMemoryManager;
ASSERT_EQ(failingMemoryManager.getCallCountFree(), 0U);
-
- uriFreeQueryListMmA(queryList, &failingMemoryManager);
-
+
+ uriFreeQueryListMmA(queryList, &failingMemoryManager);
+
ASSERT_GE(failingMemoryManager.getCallCountFree(), 1U);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, FreeUriMembersMm) {
- UriUriA uri = parse("http://example.org/");
- FailingMemoryManager failingMemoryManager;
+}
+
+
+
+TEST(FailingMemoryManagerSuite, FreeUriMembersMm) {
+ UriUriA uri = parse("http://example.org/");
+ FailingMemoryManager failingMemoryManager;
ASSERT_EQ(failingMemoryManager.getCallCountFree(), 0U);
-
- uriFreeUriMembersMmA(&uri, &failingMemoryManager);
-
+
+ uriFreeUriMembersMmA(&uri, &failingMemoryManager);
+
ASSERT_GE(failingMemoryManager.getCallCountFree(), 1U);
- uriFreeUriMembersA(&uri);
-}
-
+ uriFreeUriMembersA(&uri);
+}
+
namespace {
void testNormalizeSyntaxWithFailingMallocCallsFreeTimes(const char * uriString,
unsigned int mask,
@@ -368,28 +368,28 @@ namespace {
unsigned int expectedCallCountFree = 0) {
UriUriA uri = parse(uriString);
FailingMemoryManager failingMemoryManager(failAllocAfterTimes);
-
+
ASSERT_EQ(uriNormalizeSyntaxExMmA(&uri, mask, &failingMemoryManager),
URI_ERROR_MALLOC);
-
+
EXPECT_EQ(failingMemoryManager.getCallCountFree(), expectedCallCountFree);
-
+
uriFreeUriMembersA(&uri);
}
} // namespace
-
+
TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMmScheme) {
testNormalizeSyntaxWithFailingMallocCallsFreeTimes("hTTp://example.org/path", URI_NORMALIZE_SCHEME);
-}
-
+}
+
TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMmEmptyUserInfo) {
testNormalizeSyntaxWithFailingMallocCallsFreeTimes("//@:123", URI_NORMALIZE_USER_INFO);
}
-
+
TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMmEmptyHostRegname) {
testNormalizeSyntaxWithFailingMallocCallsFreeTimes("//:123", URI_NORMALIZE_HOST);
}
-
+
TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMmEmptyQuery) {
testNormalizeSyntaxWithFailingMallocCallsFreeTimes("//:123?", URI_NORMALIZE_QUERY);
}
@@ -416,30 +416,30 @@ TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMmHostTextFuture) { // issue #
-TEST(FailingMemoryManagerSuite, ParseSingleUriExMm) {
- UriUriA uri;
- const char * const first = "k1=v1&k2=v2";
- const char * const afterLast = first + strlen(first);
- FailingMemoryManager failingMemoryManager;
-
- ASSERT_EQ(uriParseSingleUriExMmA(&uri, first, afterLast, NULL,
- &failingMemoryManager),
- URI_ERROR_MALLOC);
-}
-
-
-
-TEST(FailingMemoryManagerSuite, RemoveBaseUriMm) {
- UriUriA dest;
- UriUriA absoluteSource = parse("http://example.org/a/b/c/");
- UriUriA absoluteBase = parse("http://example.org/a/");
- const UriBool domainRootMode = URI_TRUE; // not of interest
- FailingMemoryManager failingMemoryManager;
-
- ASSERT_EQ(uriRemoveBaseUriMmA(&dest, &absoluteSource, &absoluteBase,
- domainRootMode, &failingMemoryManager),
- URI_ERROR_MALLOC);
-
- uriFreeUriMembersA(&absoluteSource);
- uriFreeUriMembersA(&absoluteBase);
-}
+TEST(FailingMemoryManagerSuite, ParseSingleUriExMm) {
+ UriUriA uri;
+ const char * const first = "k1=v1&k2=v2";
+ const char * const afterLast = first + strlen(first);
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriParseSingleUriExMmA(&uri, first, afterLast, NULL,
+ &failingMemoryManager),
+ URI_ERROR_MALLOC);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, RemoveBaseUriMm) {
+ UriUriA dest;
+ UriUriA absoluteSource = parse("http://example.org/a/b/c/");
+ UriUriA absoluteBase = parse("http://example.org/a/");
+ const UriBool domainRootMode = URI_TRUE; // not of interest
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriRemoveBaseUriMmA(&dest, &absoluteSource, &absoluteBase,
+ domainRootMode, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeUriMembersA(&absoluteSource);
+ uriFreeUriMembersA(&absoluteBase);
+}
diff --git a/contrib/restricted/uriparser/test/VersionSuite.cpp b/contrib/restricted/uriparser/test/VersionSuite.cpp
index 014ecce385..a46f0d59b3 100644
--- a/contrib/restricted/uriparser/test/VersionSuite.cpp
+++ b/contrib/restricted/uriparser/test/VersionSuite.cpp
@@ -1,43 +1,43 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2014, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <gtest/gtest.h>
-
-#include <cstdio>
-
-
-#include <config.h> // for PACKAGE_VERSION
-#include <uriparser/UriBase.h>
-
-
-TEST(VersionSuite, EnsureVersionDefinesInSync) {
- char INSIDE_VERSION[256];
- const int bytes_printed = sprintf(INSIDE_VERSION, "%d.%d.%d%s",
- URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_ANSI);
- ASSERT_TRUE(bytes_printed != -1);
-
- const bool equal = !strcmp(INSIDE_VERSION, PACKAGE_VERSION);
- if (! equal) {
- printf("Inside/outside version mismatch detected:\n");
- printf(" Tarball version: <%s>\n", PACKAGE_VERSION);
- printf(" Header defines version: <%s>\n", INSIDE_VERSION);
- }
- ASSERT_TRUE(equal);
-}
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2014, Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <gtest/gtest.h>
+
+#include <cstdio>
+
+
+#include <config.h> // for PACKAGE_VERSION
+#include <uriparser/UriBase.h>
+
+
+TEST(VersionSuite, EnsureVersionDefinesInSync) {
+ char INSIDE_VERSION[256];
+ const int bytes_printed = sprintf(INSIDE_VERSION, "%d.%d.%d%s",
+ URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_ANSI);
+ ASSERT_TRUE(bytes_printed != -1);
+
+ const bool equal = !strcmp(INSIDE_VERSION, PACKAGE_VERSION);
+ if (! equal) {
+ printf("Inside/outside version mismatch detected:\n");
+ printf(" Tarball version: <%s>\n", PACKAGE_VERSION);
+ printf(" Header defines version: <%s>\n", INSIDE_VERSION);
+ }
+ ASSERT_TRUE(equal);
+}
diff --git a/contrib/restricted/uriparser/test/test.cpp b/contrib/restricted/uriparser/test/test.cpp
index 12166e0c1c..8580399733 100644
--- a/contrib/restricted/uriparser/test/test.cpp
+++ b/contrib/restricted/uriparser/test/test.cpp
@@ -1,1103 +1,1103 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
- * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <uriparser/Uri.h>
-#include <uriparser/UriIp4.h>
-#include <gtest/gtest.h>
-#include <memory>
-#include <cstdio>
-#include <cstdlib>
-#include <cwchar>
-
-using namespace std;
-
-
-
-extern "C" {
-UriBool uri_TESTING_ONLY_ParseIpSixA(const char * text);
-UriBool uri_TESTING_ONLY_ParseIpFourA(const char * text);
-int uriCompareRangeA(const UriTextRangeA * a, const UriTextRangeA * b);
-}
-
-
-
-#define URI_TEST_IP_FOUR_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpFourA(x))
-#define URI_TEST_IP_FOUR_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpFourA(x))
-
-// Note the closing brackets! TODO
-#define URI_TEST_IP_SIX_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
-#define URI_TEST_IP_SIX_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
-
-#define URI_EXPECT_BETWEEN(candidate, first, afterLast) \
- EXPECT_TRUE((candidate >= first) && (candidate <= afterLast))
-
-#define URI_EXPECT_OUTSIDE(candidate, first, afterLast) \
- EXPECT_TRUE((candidate < first) || (candidate > afterLast))
-
-#define URI_EXPECT_RANGE_BETWEEN(range, uriFirst, uriAfterLast) \
- URI_EXPECT_BETWEEN(range.first, uriFirst, uriAfterLast); \
- URI_EXPECT_BETWEEN(range.afterLast, uriFirst, uriAfterLast)
-
-#define URI_EXPECT_RANGE_OUTSIDE(range, uriFirst, uriAfterLast) \
- URI_EXPECT_OUTSIDE(range.first, uriFirst, uriAfterLast); \
- URI_EXPECT_OUTSIDE(range.afterLast, uriFirst, uriAfterLast)
-
-#define URI_EXPECT_RANGE_EMPTY(range) \
- EXPECT_TRUE((range.first != NULL) \
- && (range.afterLast != NULL) \
- && (range.first == range.afterLast))
-
-namespace {
- bool testDistinctionHelper(const char * uriText, bool expectedHostSet,
- bool expectedAbsPath, bool expectedEmptyTailSegment) {
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
-
- int res = uriParseUriA(&state, uriText);
- if (res != URI_SUCCESS) {
- uriFreeUriMembersA(&uri);
- return false;
- }
-
- if (expectedHostSet != (uri.hostText.first != NULL)) {
- uriFreeUriMembersA(&uri);
- return false;
- }
-
- if (expectedAbsPath != (uri.absolutePath == URI_TRUE)) {
- uriFreeUriMembersA(&uri);
- return false;
- }
-
- if (expectedEmptyTailSegment != ((uri.pathTail != NULL)
- && (uri.pathTail->text.first == uri.pathTail->text.afterLast))) {
- uriFreeUriMembersA(&uri);
- return false;
- }
-
- uriFreeUriMembersA(&uri);
- return true;
- }
-} // namespace
-
-
-TEST(UriSuite, TestDistinction) {
- /*
-============================================================================
-Rule | Example | hostSet | absPath | emptySeg
-------------------------------------|---------|---------|---------|---------
-1) URI = scheme ":" hier-part ... | | | |
- 1) "//" authority path-abempty | "s://" | true | false | false
- | "s:///" | true | false | true
- | "s://a" | true | false | false
- | "s://a/"| true | false | true
- 2) path-absolute | "s:/" | false | true | false
- 3) path-rootless | "s:a" | false | false | false
- | "s:a/" | false | false | true
- 4) path-empty | "s:" | false | false | false
-------------------------------------|---------|---------|---------|---------
-2) relative-ref = relative-part ... | | | |
- 1) "//" authority path-abempty | "//" | true | false | false
- | "///" | true | false | true
- 2) path-absolute | "/" | false | true | false
- 3) path-noscheme | "a" | false | false | false
- | "a/" | false | false | true
- 4) path-empty | "" | false | false | false
-============================================================================
- */
- ASSERT_TRUE(testDistinctionHelper("s://", true, false, false));
- ASSERT_TRUE(testDistinctionHelper("s:///", true, false, true));
- ASSERT_TRUE(testDistinctionHelper("s://a", true, false, false));
- ASSERT_TRUE(testDistinctionHelper("s://a/", true, false, true));
- ASSERT_TRUE(testDistinctionHelper("s:/", false, true, false));
- ASSERT_TRUE(testDistinctionHelper("s:a", false, false, false));
- ASSERT_TRUE(testDistinctionHelper("s:a/", false, false, true));
- ASSERT_TRUE(testDistinctionHelper("s:", false, false, false));
-
- ASSERT_TRUE(testDistinctionHelper("//", true, false, false));
- ASSERT_TRUE(testDistinctionHelper("///", true, false, true));
- ASSERT_TRUE(testDistinctionHelper("/", false, true, false));
- ASSERT_TRUE(testDistinctionHelper("a", false, false, false));
- ASSERT_TRUE(testDistinctionHelper("a/", false, false, true));
- ASSERT_TRUE(testDistinctionHelper("", false, false, false));
-}
-
-TEST(UriSuite, TestIpFour) {
- URI_TEST_IP_FOUR_FAIL("01.0.0.0");
- URI_TEST_IP_FOUR_FAIL("001.0.0.0");
- URI_TEST_IP_FOUR_FAIL("00.0.0.0");
- URI_TEST_IP_FOUR_FAIL("000.0.0.0");
- URI_TEST_IP_FOUR_FAIL("256.0.0.0");
- URI_TEST_IP_FOUR_FAIL("300.0.0.0");
- URI_TEST_IP_FOUR_FAIL("1111.0.0.0");
- URI_TEST_IP_FOUR_FAIL("-1.0.0.0");
- URI_TEST_IP_FOUR_FAIL("0.0.0");
- URI_TEST_IP_FOUR_FAIL("0.0.0.");
- URI_TEST_IP_FOUR_FAIL("0.0.0.0.");
- URI_TEST_IP_FOUR_FAIL("0.0.0.0.0");
- URI_TEST_IP_FOUR_FAIL("0.0..0");
- URI_TEST_IP_FOUR_FAIL(".0.0.0");
-
- URI_TEST_IP_FOUR_PASS("255.0.0.0");
- URI_TEST_IP_FOUR_PASS("0.0.0.0");
- URI_TEST_IP_FOUR_PASS("1.0.0.0");
- URI_TEST_IP_FOUR_PASS("2.0.0.0");
- URI_TEST_IP_FOUR_PASS("3.0.0.0");
- URI_TEST_IP_FOUR_PASS("30.0.0.0");
-}
-
-TEST(UriSuite, TestIpSixPass) {
- // Quad length
- URI_TEST_IP_SIX_PASS("abcd::");
-
- URI_TEST_IP_SIX_PASS("abcd::1");
- URI_TEST_IP_SIX_PASS("abcd::12");
- URI_TEST_IP_SIX_PASS("abcd::123");
- URI_TEST_IP_SIX_PASS("abcd::1234");
-
- // Full length
- URI_TEST_IP_SIX_PASS("2001:0db8:0100:f101:0210:a4ff:fee3:9566"); // lower hex
- URI_TEST_IP_SIX_PASS("2001:0DB8:0100:F101:0210:A4FF:FEE3:9566"); // Upper hex
- URI_TEST_IP_SIX_PASS("2001:db8:100:f101:210:a4ff:fee3:9566");
- URI_TEST_IP_SIX_PASS("2001:0db8:100:f101:0:0:0:1");
- URI_TEST_IP_SIX_PASS("1:2:3:4:5:6:255.255.255.255");
-
- // Legal IPv4
- URI_TEST_IP_SIX_PASS("::1.2.3.4");
- URI_TEST_IP_SIX_PASS("3:4::5:1.2.3.4");
- URI_TEST_IP_SIX_PASS("::ffff:1.2.3.4");
- URI_TEST_IP_SIX_PASS("::0.0.0.0"); // Min IPv4
- URI_TEST_IP_SIX_PASS("::255.255.255.255"); // Max IPv4
-
- // Zipper position
- URI_TEST_IP_SIX_PASS("::1:2:3:4:5:6:7");
- URI_TEST_IP_SIX_PASS("1::1:2:3:4:5:6");
- URI_TEST_IP_SIX_PASS("1:2::1:2:3:4:5");
- URI_TEST_IP_SIX_PASS("1:2:3::1:2:3:4");
- URI_TEST_IP_SIX_PASS("1:2:3:4::1:2:3");
- URI_TEST_IP_SIX_PASS("1:2:3:4:5::1:2");
- URI_TEST_IP_SIX_PASS("1:2:3:4:5:6::1");
- URI_TEST_IP_SIX_PASS("1:2:3:4:5:6:7::");
-
- // Zipper length
- URI_TEST_IP_SIX_PASS("1:1:1::1:1:1:1");
- URI_TEST_IP_SIX_PASS("1:1:1::1:1:1");
- URI_TEST_IP_SIX_PASS("1:1:1::1:1");
- URI_TEST_IP_SIX_PASS("1:1::1:1");
- URI_TEST_IP_SIX_PASS("1:1::1");
- URI_TEST_IP_SIX_PASS("1::1");
- URI_TEST_IP_SIX_PASS("::1"); // == localhost
- URI_TEST_IP_SIX_PASS("::"); // == all addresses
-
- // A few more variations
- URI_TEST_IP_SIX_PASS("21ff:abcd::1");
- URI_TEST_IP_SIX_PASS("2001:db8:100:f101::1");
- URI_TEST_IP_SIX_PASS("a:b:c::12:1");
- URI_TEST_IP_SIX_PASS("a:b::0:1:2:3");
-}
-
-TEST(UriSuite, TestIpSixFail) {
- // 5 char quad
- URI_TEST_IP_SIX_FAIL("::12345");
-
- // Two zippers
- URI_TEST_IP_SIX_FAIL("abcd::abcd::abcd");
-
- // Triple-colon zipper
- URI_TEST_IP_SIX_FAIL(":::1234");
- URI_TEST_IP_SIX_FAIL("1234:::1234:1234");
- URI_TEST_IP_SIX_FAIL("1234:1234:::1234");
- URI_TEST_IP_SIX_FAIL("1234:::");
-
- // No quads, just IPv4
- URI_TEST_IP_SIX_FAIL("1.2.3.4");
- URI_TEST_IP_SIX_FAIL("0001.0002.0003.0004");
-
- // Five quads
- URI_TEST_IP_SIX_FAIL("0000:0000:0000:0000:0000:1.2.3.4");
-
- // Seven quads
- URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0");
- URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0:");
- URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0:1.2.3.4");
-
- // Nine quads (or more)
- URI_TEST_IP_SIX_FAIL("1:2:3:4:5:6:7:8:9");
- URI_TEST_IP_SIX_FAIL("::2:3:4:5:6:7:8:9");
- URI_TEST_IP_SIX_FAIL("1:2:3:4::6:7:8:9");
- URI_TEST_IP_SIX_FAIL("1:2:3:4:5:6:7:8::");
-
- // Invalid IPv4 part
- URI_TEST_IP_SIX_FAIL("::ffff:001.02.03.004"); // Leading zeros
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.1111"); // Four char octet
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.256"); // > 255
- URI_TEST_IP_SIX_FAIL("::ffff:311.2.3.4"); // > 155
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3:4"); // Not a dot
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3"); // Missing octet
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3."); // Missing octet
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3a.4"); // Hex in octet
- URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.4:123"); // Crap input
-
- // Nonhex
- URI_TEST_IP_SIX_FAIL("g:0:0:0:0:0:0");
-}
-
-TEST(UriSuite, TestIpSixOverread) {
- UriUriA uri;
- const char * errorPos;
-
- // NOTE: This string is designed to not have a terminator
- char uriText[2 + 3 + 2 + 1 + 1];
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <uriparser/Uri.h>
+#include <uriparser/UriIp4.h>
+#include <gtest/gtest.h>
+#include <memory>
+#include <cstdio>
+#include <cstdlib>
+#include <cwchar>
+
+using namespace std;
+
+
+
+extern "C" {
+UriBool uri_TESTING_ONLY_ParseIpSixA(const char * text);
+UriBool uri_TESTING_ONLY_ParseIpFourA(const char * text);
+int uriCompareRangeA(const UriTextRangeA * a, const UriTextRangeA * b);
+}
+
+
+
+#define URI_TEST_IP_FOUR_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpFourA(x))
+#define URI_TEST_IP_FOUR_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpFourA(x))
+
+// Note the closing brackets! TODO
+#define URI_TEST_IP_SIX_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
+#define URI_TEST_IP_SIX_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
+
+#define URI_EXPECT_BETWEEN(candidate, first, afterLast) \
+ EXPECT_TRUE((candidate >= first) && (candidate <= afterLast))
+
+#define URI_EXPECT_OUTSIDE(candidate, first, afterLast) \
+ EXPECT_TRUE((candidate < first) || (candidate > afterLast))
+
+#define URI_EXPECT_RANGE_BETWEEN(range, uriFirst, uriAfterLast) \
+ URI_EXPECT_BETWEEN(range.first, uriFirst, uriAfterLast); \
+ URI_EXPECT_BETWEEN(range.afterLast, uriFirst, uriAfterLast)
+
+#define URI_EXPECT_RANGE_OUTSIDE(range, uriFirst, uriAfterLast) \
+ URI_EXPECT_OUTSIDE(range.first, uriFirst, uriAfterLast); \
+ URI_EXPECT_OUTSIDE(range.afterLast, uriFirst, uriAfterLast)
+
+#define URI_EXPECT_RANGE_EMPTY(range) \
+ EXPECT_TRUE((range.first != NULL) \
+ && (range.afterLast != NULL) \
+ && (range.first == range.afterLast))
+
+namespace {
+ bool testDistinctionHelper(const char * uriText, bool expectedHostSet,
+ bool expectedAbsPath, bool expectedEmptyTailSegment) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+
+ int res = uriParseUriA(&state, uriText);
+ if (res != URI_SUCCESS) {
+ uriFreeUriMembersA(&uri);
+ return false;
+ }
+
+ if (expectedHostSet != (uri.hostText.first != NULL)) {
+ uriFreeUriMembersA(&uri);
+ return false;
+ }
+
+ if (expectedAbsPath != (uri.absolutePath == URI_TRUE)) {
+ uriFreeUriMembersA(&uri);
+ return false;
+ }
+
+ if (expectedEmptyTailSegment != ((uri.pathTail != NULL)
+ && (uri.pathTail->text.first == uri.pathTail->text.afterLast))) {
+ uriFreeUriMembersA(&uri);
+ return false;
+ }
+
+ uriFreeUriMembersA(&uri);
+ return true;
+ }
+} // namespace
+
+
+TEST(UriSuite, TestDistinction) {
+ /*
+============================================================================
+Rule | Example | hostSet | absPath | emptySeg
+------------------------------------|---------|---------|---------|---------
+1) URI = scheme ":" hier-part ... | | | |
+ 1) "//" authority path-abempty | "s://" | true | false | false
+ | "s:///" | true | false | true
+ | "s://a" | true | false | false
+ | "s://a/"| true | false | true
+ 2) path-absolute | "s:/" | false | true | false
+ 3) path-rootless | "s:a" | false | false | false
+ | "s:a/" | false | false | true
+ 4) path-empty | "s:" | false | false | false
+------------------------------------|---------|---------|---------|---------
+2) relative-ref = relative-part ... | | | |
+ 1) "//" authority path-abempty | "//" | true | false | false
+ | "///" | true | false | true
+ 2) path-absolute | "/" | false | true | false
+ 3) path-noscheme | "a" | false | false | false
+ | "a/" | false | false | true
+ 4) path-empty | "" | false | false | false
+============================================================================
+ */
+ ASSERT_TRUE(testDistinctionHelper("s://", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s:///", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s://a", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s://a/", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s:/", false, true, false));
+ ASSERT_TRUE(testDistinctionHelper("s:a", false, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s:a/", false, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s:", false, false, false));
+
+ ASSERT_TRUE(testDistinctionHelper("//", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("///", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("/", false, true, false));
+ ASSERT_TRUE(testDistinctionHelper("a", false, false, false));
+ ASSERT_TRUE(testDistinctionHelper("a/", false, false, true));
+ ASSERT_TRUE(testDistinctionHelper("", false, false, false));
+}
+
+TEST(UriSuite, TestIpFour) {
+ URI_TEST_IP_FOUR_FAIL("01.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("001.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("00.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("000.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("256.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("300.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("1111.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("-1.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("0.0.0");
+ URI_TEST_IP_FOUR_FAIL("0.0.0.");
+ URI_TEST_IP_FOUR_FAIL("0.0.0.0.");
+ URI_TEST_IP_FOUR_FAIL("0.0.0.0.0");
+ URI_TEST_IP_FOUR_FAIL("0.0..0");
+ URI_TEST_IP_FOUR_FAIL(".0.0.0");
+
+ URI_TEST_IP_FOUR_PASS("255.0.0.0");
+ URI_TEST_IP_FOUR_PASS("0.0.0.0");
+ URI_TEST_IP_FOUR_PASS("1.0.0.0");
+ URI_TEST_IP_FOUR_PASS("2.0.0.0");
+ URI_TEST_IP_FOUR_PASS("3.0.0.0");
+ URI_TEST_IP_FOUR_PASS("30.0.0.0");
+}
+
+TEST(UriSuite, TestIpSixPass) {
+ // Quad length
+ URI_TEST_IP_SIX_PASS("abcd::");
+
+ URI_TEST_IP_SIX_PASS("abcd::1");
+ URI_TEST_IP_SIX_PASS("abcd::12");
+ URI_TEST_IP_SIX_PASS("abcd::123");
+ URI_TEST_IP_SIX_PASS("abcd::1234");
+
+ // Full length
+ URI_TEST_IP_SIX_PASS("2001:0db8:0100:f101:0210:a4ff:fee3:9566"); // lower hex
+ URI_TEST_IP_SIX_PASS("2001:0DB8:0100:F101:0210:A4FF:FEE3:9566"); // Upper hex
+ URI_TEST_IP_SIX_PASS("2001:db8:100:f101:210:a4ff:fee3:9566");
+ URI_TEST_IP_SIX_PASS("2001:0db8:100:f101:0:0:0:1");
+ URI_TEST_IP_SIX_PASS("1:2:3:4:5:6:255.255.255.255");
+
+ // Legal IPv4
+ URI_TEST_IP_SIX_PASS("::1.2.3.4");
+ URI_TEST_IP_SIX_PASS("3:4::5:1.2.3.4");
+ URI_TEST_IP_SIX_PASS("::ffff:1.2.3.4");
+ URI_TEST_IP_SIX_PASS("::0.0.0.0"); // Min IPv4
+ URI_TEST_IP_SIX_PASS("::255.255.255.255"); // Max IPv4
+
+ // Zipper position
+ URI_TEST_IP_SIX_PASS("::1:2:3:4:5:6:7");
+ URI_TEST_IP_SIX_PASS("1::1:2:3:4:5:6");
+ URI_TEST_IP_SIX_PASS("1:2::1:2:3:4:5");
+ URI_TEST_IP_SIX_PASS("1:2:3::1:2:3:4");
+ URI_TEST_IP_SIX_PASS("1:2:3:4::1:2:3");
+ URI_TEST_IP_SIX_PASS("1:2:3:4:5::1:2");
+ URI_TEST_IP_SIX_PASS("1:2:3:4:5:6::1");
+ URI_TEST_IP_SIX_PASS("1:2:3:4:5:6:7::");
+
+ // Zipper length
+ URI_TEST_IP_SIX_PASS("1:1:1::1:1:1:1");
+ URI_TEST_IP_SIX_PASS("1:1:1::1:1:1");
+ URI_TEST_IP_SIX_PASS("1:1:1::1:1");
+ URI_TEST_IP_SIX_PASS("1:1::1:1");
+ URI_TEST_IP_SIX_PASS("1:1::1");
+ URI_TEST_IP_SIX_PASS("1::1");
+ URI_TEST_IP_SIX_PASS("::1"); // == localhost
+ URI_TEST_IP_SIX_PASS("::"); // == all addresses
+
+ // A few more variations
+ URI_TEST_IP_SIX_PASS("21ff:abcd::1");
+ URI_TEST_IP_SIX_PASS("2001:db8:100:f101::1");
+ URI_TEST_IP_SIX_PASS("a:b:c::12:1");
+ URI_TEST_IP_SIX_PASS("a:b::0:1:2:3");
+}
+
+TEST(UriSuite, TestIpSixFail) {
+ // 5 char quad
+ URI_TEST_IP_SIX_FAIL("::12345");
+
+ // Two zippers
+ URI_TEST_IP_SIX_FAIL("abcd::abcd::abcd");
+
+ // Triple-colon zipper
+ URI_TEST_IP_SIX_FAIL(":::1234");
+ URI_TEST_IP_SIX_FAIL("1234:::1234:1234");
+ URI_TEST_IP_SIX_FAIL("1234:1234:::1234");
+ URI_TEST_IP_SIX_FAIL("1234:::");
+
+ // No quads, just IPv4
+ URI_TEST_IP_SIX_FAIL("1.2.3.4");
+ URI_TEST_IP_SIX_FAIL("0001.0002.0003.0004");
+
+ // Five quads
+ URI_TEST_IP_SIX_FAIL("0000:0000:0000:0000:0000:1.2.3.4");
+
+ // Seven quads
+ URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0");
+ URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0:");
+ URI_TEST_IP_SIX_FAIL("0:0:0:0:0:0:0:1.2.3.4");
+
+ // Nine quads (or more)
+ URI_TEST_IP_SIX_FAIL("1:2:3:4:5:6:7:8:9");
+ URI_TEST_IP_SIX_FAIL("::2:3:4:5:6:7:8:9");
+ URI_TEST_IP_SIX_FAIL("1:2:3:4::6:7:8:9");
+ URI_TEST_IP_SIX_FAIL("1:2:3:4:5:6:7:8::");
+
+ // Invalid IPv4 part
+ URI_TEST_IP_SIX_FAIL("::ffff:001.02.03.004"); // Leading zeros
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.1111"); // Four char octet
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.256"); // > 255
+ URI_TEST_IP_SIX_FAIL("::ffff:311.2.3.4"); // > 155
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3:4"); // Not a dot
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3"); // Missing octet
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3."); // Missing octet
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3a.4"); // Hex in octet
+ URI_TEST_IP_SIX_FAIL("::ffff:1.2.3.4:123"); // Crap input
+
+ // Nonhex
+ URI_TEST_IP_SIX_FAIL("g:0:0:0:0:0:0");
+}
+
+TEST(UriSuite, TestIpSixOverread) {
+ UriUriA uri;
+ const char * errorPos;
+
+ // NOTE: This string is designed to not have a terminator
+ char uriText[2 + 3 + 2 + 1 + 1];
memcpy(uriText, "//[::44.1", sizeof(uriText));
-
- EXPECT_EQ(uriParseSingleUriExA(&uri, uriText,
- uriText + sizeof(uriText), &errorPos), URI_ERROR_SYNTAX);
- EXPECT_EQ(errorPos, uriText + sizeof(uriText));
-}
-
-TEST(UriSuite, TestUri) {
- UriParserStateA stateA;
- UriParserStateW stateW;
- UriUriA uriA;
- UriUriW uriW;
-
- stateA.uri = &uriA;
- stateW.uri = &uriW;
-
- // On/off for each
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@[::1]:80/segment/index.html?query#frag"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://[::1]:80/segment/index.html?query#frag"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]/segment/index.html?query#frag"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80?query#frag"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html#frag"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html?query"));
- uriFreeUriMembersA(&uriA);
-
- // Schema, port, one segment
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "ftp://host:21/gnu/"));
- uriFreeUriMembersA(&uriA);
-
- // Relative
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "one/two/three"));
- ASSERT_TRUE(!uriA.absolutePath);
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "/one/two/three"));
- ASSERT_TRUE(uriA.absolutePath);
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@localhost/one/two/three"));
- uriFreeUriMembersA(&uriA);
-
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, uriText,
+ uriText + sizeof(uriText), &errorPos), URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriText + sizeof(uriText));
+}
+
+TEST(UriSuite, TestUri) {
+ UriParserStateA stateA;
+ UriParserStateW stateW;
+ UriUriA uriA;
+ UriUriW uriW;
+
+ stateA.uri = &uriA;
+ stateW.uri = &uriW;
+
+ // On/off for each
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@[::1]:80/segment/index.html?query#frag"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://[::1]:80/segment/index.html?query#frag"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]/segment/index.html?query#frag"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80?query#frag"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html#frag"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html?query"));
+ uriFreeUriMembersA(&uriA);
+
+ // Schema, port, one segment
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "ftp://host:21/gnu/"));
+ uriFreeUriMembersA(&uriA);
+
+ // Relative
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "one/two/three"));
+ ASSERT_TRUE(!uriA.absolutePath);
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "/one/two/three"));
+ ASSERT_TRUE(uriA.absolutePath);
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@localhost/one/two/three"));
+ uriFreeUriMembersA(&uriA);
+
// Both narrow and wide string version
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriW(&stateW, L"http://www.example.com/"));
- uriFreeUriMembersW(&uriW);
-
- // Real life examples
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/projects/uriparser/"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/project/platformdownload.php?group_id=182840"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "mailto:test@example.com"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "../../"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "/"));
- ASSERT_TRUE(uriA.absolutePath);
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, ""));
- ASSERT_TRUE(!uriA.absolutePath);
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "file:///bin/bash"));
- uriFreeUriMembersA(&uriA);
-
- // Percent encoding
- ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/name%20with%20spaces/"));
- uriFreeUriMembersA(&uriA);
- ASSERT_TRUE(0 != uriParseUriA(&stateA, "http://www.example.com/name with spaces/"));
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriComponents) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 15 01 0 7 01
- const char * const input = "http" "://" "sourceforge.net" "/" "project" "/"
- // 0 20 01 0 15
- "platformdownload.php" "?" "group_id=182840";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.scheme.first == input);
- ASSERT_TRUE(uriA.scheme.afterLast == input + 4);
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 15);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
-
- ASSERT_TRUE(uriA.pathHead->text.first == input + 4 + 3 + 15 + 1);
- ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 4 + 3 + 15 + 1 + 7);
- ASSERT_TRUE(uriA.pathHead->next->text.first == input + 4 + 3 + 15 + 1 + 7 + 1);
- ASSERT_TRUE(uriA.pathHead->next->text.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20);
- ASSERT_TRUE(uriA.pathHead->next->next == NULL);
- ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
-
- ASSERT_TRUE(uriA.query.first == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1);
- ASSERT_TRUE(uriA.query.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1 + 15);
- ASSERT_TRUE(uriA.fragment.first == NULL);
- ASSERT_TRUE(uriA.fragment.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriComponentsBug20070701) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 01 01 01
- const char * const input = "a" ":" "b";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.scheme.first == input);
- ASSERT_TRUE(uriA.scheme.afterLast == input + 1);
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.hostText.first == NULL);
- ASSERT_TRUE(uriA.hostText.afterLast == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
-
- ASSERT_TRUE(uriA.pathHead->text.first == input + 1 + 1);
- ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 1 + 1 + 1);
- ASSERT_TRUE(uriA.pathHead->next == NULL);
- ASSERT_TRUE(uriA.pathTail == uriA.pathHead);
-
- ASSERT_TRUE(uriA.query.first == NULL);
- ASSERT_TRUE(uriA.query.afterLast == NULL);
- ASSERT_TRUE(uriA.fragment.first == NULL);
- ASSERT_TRUE(uriA.fragment.afterLast == NULL);
-
- ASSERT_TRUE(!uriA.absolutePath);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort1) {
- // User info with ":", no port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7 01 0 9
- const char * const input = "http" "://" "abc:def" "@" "localhost";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
- ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort2) {
- // User info with ":", with port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7 01 0 9
- const char * const input = "http" "://" "abc:def" "@" "localhost"
- // 01 0 3
- ":" "123";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
- ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
- ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort22Bug1948038) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
-
- res = uriParseUriA(&stateA, "http://user:21@host/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:21", 7 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 7);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-
- res = uriParseUriA(&stateA, "http://user:1234@192.168.0.1:1234/foo.com");
- ASSERT_TRUE(URI_SUCCESS == res);
- uriFreeUriMembersA(&uriA);
-
- res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo/");
- ASSERT_TRUE(URI_ERROR_SYNTAX == res);
- uriFreeUriMembersA(&uriA);
-
- res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo:21/");
- ASSERT_TRUE(URI_ERROR_SYNTAX == res);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198One) {
- // User info with ":", with port, with escaped chars in password
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 10 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "user:%2F21" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:%2F21", 10 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 10);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Two) {
- // User info with ":", with port, with escaped chars in user name and password
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 13 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "%2Fuser:%2F21" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "%2Fuser:%2F21", 13 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 13);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Three) {
- // User info with ":", with port, with escaped chars in password
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 16 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "user:!$&'()*+,;=" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:!$&'()*+,;=", 16 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 16);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Four) {
- // User info with ":", with port, with escaped chars in user name and password
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 20 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "!$&'()*+,;=:password" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "!$&'()*+,;=:password", 20 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 20);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOne) {
- // Empty user info
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(uriA.userInfo.afterLast != NULL);
- ASSERT_TRUE(uriA.userInfo.first != NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 0);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOneTwo) {
- // Empty user info
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 7 01
- res = uriParseUriA(&stateA, "http" "://" "%2Fhost" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "%2Fhost", 7 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 7);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedTwo) {
- // Several colons in userinfo
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
-
- int res;
- // 0 4 0 3 0 2 01 0 4 01
- res = uriParseUriA(&stateA, "http" "://" "::" "@" "host" "/");
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(!memcmp(uriA.userInfo.first, "::", 2 * sizeof(char)));
- ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 2);
- ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort3) {
- // User info without ":", no port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7 01 0 9
- const char * const input = "http" "://" "abcdefg" "@" "localhost";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
- ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort4) {
- // User info without ":", with port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7 01 0 9
- const char * const input = "http" "://" "abcdefg" "@" "localhost"
- // 01 0 3
- ":" "123";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
- ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
- ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort5) {
- // No user info, no port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 9
- const char * const input = "http" "://" "localhost";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
- ASSERT_TRUE(uriA.portText.first == NULL);
- ASSERT_TRUE(uriA.portText.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriUserInfoHostPort6) {
- // No user info, with port
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 9 01 0 3
- const char * const input = "http" "://" "localhost" ":" "123";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
- ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 9 + 1);
- ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 9 + 1 + 3);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostRegname) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 11
- const char * const input = "http" "://" "example.com";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 11);
- ASSERT_TRUE(uriA.hostData.ip4 == NULL);
- ASSERT_TRUE(uriA.hostData.ip6 == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostIpFour1) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7 01 0 2
- const char * const input = "http" "://" "1.2.3.4" ":" "80";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostData.ip4 != NULL);
- ASSERT_TRUE(uriA.hostData.ip6 == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostIpFour2) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 0 7
- const char * const input = "http" "://" "1.2.3.4";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
- ASSERT_TRUE(uriA.hostData.ip4 != NULL);
- ASSERT_TRUE(uriA.hostData.ip6 == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostIpSix1) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 01 45 01 0 2
- const char * const input = "http" "://" "[::1]" ":" "80";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
- ASSERT_TRUE(uriA.hostData.ip4 == NULL);
- ASSERT_TRUE(uriA.hostData.ip6 != NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostIpSix2) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 01 45
- const char * const input = "http" "://" "[::1]";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
- ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
- ASSERT_TRUE(uriA.hostData.ip4 == NULL);
- ASSERT_TRUE(uriA.hostData.ip6 != NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
- ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostEmpty) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 4 0 3 01 0 3
- const char * const input = "http" "://" ":" "123";
- const int res = uriParseUriA(&stateA, input);
- ASSERT_TRUE(URI_SUCCESS == res);
- ASSERT_TRUE(uriA.userInfo.first == NULL);
- ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
- ASSERT_TRUE(uriA.hostText.first != NULL);
- ASSERT_TRUE(uriA.hostText.afterLast != NULL);
- ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 0);
- ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 1);
- ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 1 + 3);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestUriHostIpFuture) {
- // TODO
-}
-
-namespace {
- bool testEscapingHelper(const wchar_t * in, const wchar_t * expectedOut,
- bool spaceToPlus = false, bool normalizeBreaks = false) {
- wchar_t * const buffer = new wchar_t[(normalizeBreaks ? 6 : 3)
- * wcslen(in) + 1];
- if (uriEscapeW(in, buffer, spaceToPlus, normalizeBreaks)
- != buffer + wcslen(expectedOut)) {
- delete [] buffer;
- return false;
- }
-
- const bool equal = !wcscmp(buffer, expectedOut);
- delete [] buffer;
- return equal;
- }
-} // namespace
-
-TEST(UriSuite, TestEscaping) {
- const bool SPACE_TO_PLUS = true;
- const bool SPACE_TO_PERCENT = false;
- const bool KEEP_UNMODIFIED = false;
- const bool NORMALIZE = true;
-
- // '+' to ' '
- ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc+def", SPACE_TO_PLUS));
- ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc%20def", SPACE_TO_PERCENT));
-
- // Percent encoding
- ASSERT_TRUE(testEscapingHelper(L"\x00", L"\0"));
- ASSERT_TRUE(testEscapingHelper(L"\x01", L"%01"));
- ASSERT_TRUE(testEscapingHelper(L"\xff", L"%FF"));
-
- // Linebreak normalization
- ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0D%0A%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0A%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-}
-
-namespace {
- bool testUnescapingHelper(const wchar_t * input, const wchar_t * output,
- bool plusToSpace = false, UriBreakConversion breakConversion = URI_BR_DONT_TOUCH) {
- wchar_t * working = new wchar_t[URI_STRLEN(input) + 1];
- wcscpy(working, input);
- const wchar_t * newTermZero = uriUnescapeInPlaceExW(working,
- plusToSpace ? URI_TRUE : URI_FALSE, breakConversion);
- const bool success = ((newTermZero == working + wcslen(output))
- && !wcscmp(working, output));
- delete[] working;
- return success;
- }
-} // namespace
-
-TEST(UriSuite, TestUnescaping) {
- const bool PLUS_TO_SPACE = true;
- const bool PLUS_DONT_TOUCH = false;
-
-
- // Proper
- ASSERT_TRUE(testUnescapingHelper(L"abc%20%41BC", L"abc ABC"));
- ASSERT_TRUE(testUnescapingHelper(L"%20", L" "));
-
- // Incomplete
- ASSERT_TRUE(testUnescapingHelper(L"%0", L"%0"));
-
- // Nonhex
- ASSERT_TRUE(testUnescapingHelper(L"%0g", L"%0g"));
- ASSERT_TRUE(testUnescapingHelper(L"%G0", L"%G0"));
-
- // No double decoding
- ASSERT_TRUE(testUnescapingHelper(L"%2520", L"%20"));
-
- // Decoding of '+'
- ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc+def", PLUS_DONT_TOUCH));
- ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc def", PLUS_TO_SPACE));
-
- // Line break conversion
- ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-}
-
-namespace {
- bool testAddBaseHelper(const wchar_t * base, const wchar_t * rel, const wchar_t * expectedResult, bool backward_compatibility = false) {
- UriParserStateW stateW;
-
- // Base
- UriUriW baseUri;
- stateW.uri = &baseUri;
- int res = uriParseUriW(&stateW, base);
- if (res != 0) {
- uriFreeUriMembersW(&baseUri);
- return false;
- }
-
- // Rel
- UriUriW relUri;
- stateW.uri = &relUri;
- res = uriParseUriW(&stateW, rel);
- if (res != 0) {
- uriFreeUriMembersW(&baseUri);
- uriFreeUriMembersW(&relUri);
- return false;
- }
-
- // Expected result
- UriUriW expectedUri;
- stateW.uri = &expectedUri;
- res = uriParseUriW(&stateW, expectedResult);
- if (res != 0) {
- uriFreeUriMembersW(&baseUri);
- uriFreeUriMembersW(&relUri);
- uriFreeUriMembersW(&expectedUri);
- return false;
- }
-
- // Transform
- UriUriW transformedUri;
- if (backward_compatibility) {
- res = uriAddBaseUriExW(&transformedUri, &relUri, &baseUri, URI_RESOLVE_IDENTICAL_SCHEME_COMPAT);
- } else {
- res = uriAddBaseUriW(&transformedUri, &relUri, &baseUri);
- }
-
- if (res != 0) {
- uriFreeUriMembersW(&baseUri);
- uriFreeUriMembersW(&relUri);
- uriFreeUriMembersW(&expectedUri);
- uriFreeUriMembersW(&transformedUri);
- return false;
- }
-
- const bool equal = (URI_TRUE == uriEqualsUriW(&transformedUri, &expectedUri));
- if (!equal) {
- wchar_t transformedUriText[1024 * 8];
- wchar_t expectedUriText[1024 * 8];
- uriToStringW(transformedUriText, &transformedUri, 1024 * 8, NULL);
- uriToStringW(expectedUriText, &expectedUri, 1024 * 8, NULL);
-#ifdef HAVE_WPRINTF
- wprintf(L"\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
-#endif
- }
-
- uriFreeUriMembersW(&baseUri);
- uriFreeUriMembersW(&relUri);
- uriFreeUriMembersW(&expectedUri);
- uriFreeUriMembersW(&transformedUri);
- return equal;
- }
-} // namespace
-
-TEST(UriSuite, TestTrailingSlash) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- // 0 3 01
- const char * const input = "abc" "/";
- ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
-
- ASSERT_TRUE(uriA.pathHead->text.first == input);
- ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 3);
- ASSERT_TRUE(uriA.pathHead->next->text.first == uriA.pathHead->next->text.afterLast);
- ASSERT_TRUE(uriA.pathHead->next->next == NULL);
- ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
- uriFreeUriMembersA(&uriA);
-}
-
-TEST(UriSuite, TestAddBase) {
- // 5.4.1. Normal Examples
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g:h", L"g:h"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g", L"http://a/b/c/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g", L"http://a/b/c/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/", L"http://a/b/c/g/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g", L"http://a/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"//g", L"http://g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"?y", L"http://a/b/c/d;p?y"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y", L"http://a/b/c/g?y"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"#s", L"http://a/b/c/d;p?q#s"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s", L"http://a/b/c/g#s"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y#s", L"http://a/b/c/g?y#s"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L";x", L"http://a/b/c/;x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x", L"http://a/b/c/g;x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x?y#s", L"http://a/b/c/g;x?y#s"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"", L"http://a/b/c/d;p?q"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".", L"http://a/b/c/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./", L"http://a/b/c/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..", L"http://a/b/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../", L"http://a/b/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../g", L"http://a/b/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../..", L"http://a/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../", L"http://a/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../g", L"http://a/g"));
-
- // 5.4.2. Abnormal Examples
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../g", L"http://a/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../../g", L"http://a/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/./g", L"http://a/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/../g", L"http://a/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g.", L"http://a/b/c/g."));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".g", L"http://a/b/c/.g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g..", L"http://a/b/c/g.."));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..g", L"http://a/b/c/..g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./../g", L"http://a/b/g"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g/.", L"http://a/b/c/g/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/./h", L"http://a/b/c/g/h"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/../h", L"http://a/b/c/h"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/./y", L"http://a/b/c/g;x=1/y"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/../y", L"http://a/b/c/y"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/./x", L"http://a/b/c/g?y/./x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/../x", L"http://a/b/c/g?y/../x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/./x", L"http://a/b/c/g#s/./x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/../x", L"http://a/b/c/g#s/../x"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g"));
-
- // Backward compatibility (feature request #4, RFC3986 5.4.2)
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g", false));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http://a/b/c/g", true));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g?q#f", L"http://a/b/c/g?q#f", true));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"other:g?q#f", L"other:g?q#f", true));
-
- // Bug related to absolutePath flag set despite presence of host
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/", L"http://a/"));
- ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g/", L"http://a/g/"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriW(&stateW, L"http://www.example.com/"));
+ uriFreeUriMembersW(&uriW);
+
+ // Real life examples
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/projects/uriparser/"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/project/platformdownload.php?group_id=182840"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "mailto:test@example.com"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "../../"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "/"));
+ ASSERT_TRUE(uriA.absolutePath);
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, ""));
+ ASSERT_TRUE(!uriA.absolutePath);
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "file:///bin/bash"));
+ uriFreeUriMembersA(&uriA);
+
+ // Percent encoding
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/name%20with%20spaces/"));
+ uriFreeUriMembersA(&uriA);
+ ASSERT_TRUE(0 != uriParseUriA(&stateA, "http://www.example.com/name with spaces/"));
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriComponents) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 15 01 0 7 01
+ const char * const input = "http" "://" "sourceforge.net" "/" "project" "/"
+ // 0 20 01 0 15
+ "platformdownload.php" "?" "group_id=182840";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.scheme.first == input);
+ ASSERT_TRUE(uriA.scheme.afterLast == input + 4);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 15);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+
+ ASSERT_TRUE(uriA.pathHead->text.first == input + 4 + 3 + 15 + 1);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 4 + 3 + 15 + 1 + 7);
+ ASSERT_TRUE(uriA.pathHead->next->text.first == input + 4 + 3 + 15 + 1 + 7 + 1);
+ ASSERT_TRUE(uriA.pathHead->next->text.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20);
+ ASSERT_TRUE(uriA.pathHead->next->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
+
+ ASSERT_TRUE(uriA.query.first == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1);
+ ASSERT_TRUE(uriA.query.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1 + 15);
+ ASSERT_TRUE(uriA.fragment.first == NULL);
+ ASSERT_TRUE(uriA.fragment.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriComponentsBug20070701) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 01 01 01
+ const char * const input = "a" ":" "b";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.scheme.first == input);
+ ASSERT_TRUE(uriA.scheme.afterLast == input + 1);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+
+ ASSERT_TRUE(uriA.pathHead->text.first == input + 1 + 1);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 1 + 1 + 1);
+ ASSERT_TRUE(uriA.pathHead->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead);
+
+ ASSERT_TRUE(uriA.query.first == NULL);
+ ASSERT_TRUE(uriA.query.afterLast == NULL);
+ ASSERT_TRUE(uriA.fragment.first == NULL);
+ ASSERT_TRUE(uriA.fragment.afterLast == NULL);
+
+ ASSERT_TRUE(!uriA.absolutePath);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort1) {
+ // User info with ":", no port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7 01 0 9
+ const char * const input = "http" "://" "abc:def" "@" "localhost";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort2) {
+ // User info with ":", with port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7 01 0 9
+ const char * const input = "http" "://" "abc:def" "@" "localhost"
+ // 01 0 3
+ ":" "123";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort22Bug1948038) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+
+ res = uriParseUriA(&stateA, "http://user:21@host/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:21", 7 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 7);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+
+ res = uriParseUriA(&stateA, "http://user:1234@192.168.0.1:1234/foo.com");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ uriFreeUriMembersA(&uriA);
+
+ res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo/");
+ ASSERT_TRUE(URI_ERROR_SYNTAX == res);
+ uriFreeUriMembersA(&uriA);
+
+ res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo:21/");
+ ASSERT_TRUE(URI_ERROR_SYNTAX == res);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198One) {
+ // User info with ":", with port, with escaped chars in password
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 10 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "user:%2F21" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:%2F21", 10 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 10);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Two) {
+ // User info with ":", with port, with escaped chars in user name and password
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 13 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "%2Fuser:%2F21" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "%2Fuser:%2F21", 13 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 13);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Three) {
+ // User info with ":", with port, with escaped chars in password
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 16 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "user:!$&'()*+,;=" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:!$&'()*+,;=", 16 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 16);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Four) {
+ // User info with ":", with port, with escaped chars in user name and password
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 20 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "!$&'()*+,;=:password" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "!$&'()*+,;=:password", 20 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 20);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOne) {
+ // Empty user info
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.afterLast != NULL);
+ ASSERT_TRUE(uriA.userInfo.first != NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 0);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOneTwo) {
+ // Empty user info
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 7 01
+ res = uriParseUriA(&stateA, "http" "://" "%2Fhost" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "%2Fhost", 7 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 7);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedTwo) {
+ // Several colons in userinfo
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+
+ int res;
+ // 0 4 0 3 0 2 01 0 4 01
+ res = uriParseUriA(&stateA, "http" "://" "::" "@" "host" "/");
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "::", 2 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 2);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort3) {
+ // User info without ":", no port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7 01 0 9
+ const char * const input = "http" "://" "abcdefg" "@" "localhost";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort4) {
+ // User info without ":", with port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7 01 0 9
+ const char * const input = "http" "://" "abcdefg" "@" "localhost"
+ // 01 0 3
+ ":" "123";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort5) {
+ // No user info, no port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 9
+ const char * const input = "http" "://" "localhost";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriUserInfoHostPort6) {
+ // No user info, with port
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 9 01 0 3
+ const char * const input = "http" "://" "localhost" ":" "123";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 9 + 1 + 3);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostRegname) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 11
+ const char * const input = "http" "://" "example.com";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 11);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostIpFour1) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7 01 0 2
+ const char * const input = "http" "://" "1.2.3.4" ":" "80";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostData.ip4 != NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostIpFour2) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 0 7
+ const char * const input = "http" "://" "1.2.3.4";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostData.ip4 != NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostIpSix1) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 01 45 01 0 2
+ const char * const input = "http" "://" "[::1]" ":" "80";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 != NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostIpSix2) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 01 45
+ const char * const input = "http" "://" "[::1]";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 != NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostEmpty) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 4 0 3 01 0 3
+ const char * const input = "http" "://" ":" "123";
+ const int res = uriParseUriA(&stateA, input);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first != NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast != NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 0);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 1 + 3);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestUriHostIpFuture) {
+ // TODO
+}
+
+namespace {
+ bool testEscapingHelper(const wchar_t * in, const wchar_t * expectedOut,
+ bool spaceToPlus = false, bool normalizeBreaks = false) {
+ wchar_t * const buffer = new wchar_t[(normalizeBreaks ? 6 : 3)
+ * wcslen(in) + 1];
+ if (uriEscapeW(in, buffer, spaceToPlus, normalizeBreaks)
+ != buffer + wcslen(expectedOut)) {
+ delete [] buffer;
+ return false;
+ }
+
+ const bool equal = !wcscmp(buffer, expectedOut);
+ delete [] buffer;
+ return equal;
+ }
+} // namespace
+
+TEST(UriSuite, TestEscaping) {
+ const bool SPACE_TO_PLUS = true;
+ const bool SPACE_TO_PERCENT = false;
+ const bool KEEP_UNMODIFIED = false;
+ const bool NORMALIZE = true;
+
+ // '+' to ' '
+ ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc+def", SPACE_TO_PLUS));
+ ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc%20def", SPACE_TO_PERCENT));
+
+ // Percent encoding
+ ASSERT_TRUE(testEscapingHelper(L"\x00", L"\0"));
+ ASSERT_TRUE(testEscapingHelper(L"\x01", L"%01"));
+ ASSERT_TRUE(testEscapingHelper(L"\xff", L"%FF"));
+
+ // Linebreak normalization
+ ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0D%0A%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0A%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+}
+
+namespace {
+ bool testUnescapingHelper(const wchar_t * input, const wchar_t * output,
+ bool plusToSpace = false, UriBreakConversion breakConversion = URI_BR_DONT_TOUCH) {
+ wchar_t * working = new wchar_t[URI_STRLEN(input) + 1];
+ wcscpy(working, input);
+ const wchar_t * newTermZero = uriUnescapeInPlaceExW(working,
+ plusToSpace ? URI_TRUE : URI_FALSE, breakConversion);
+ const bool success = ((newTermZero == working + wcslen(output))
+ && !wcscmp(working, output));
+ delete[] working;
+ return success;
+ }
+} // namespace
+
+TEST(UriSuite, TestUnescaping) {
+ const bool PLUS_TO_SPACE = true;
+ const bool PLUS_DONT_TOUCH = false;
+
+
+ // Proper
+ ASSERT_TRUE(testUnescapingHelper(L"abc%20%41BC", L"abc ABC"));
+ ASSERT_TRUE(testUnescapingHelper(L"%20", L" "));
+
+ // Incomplete
+ ASSERT_TRUE(testUnescapingHelper(L"%0", L"%0"));
+
+ // Nonhex
+ ASSERT_TRUE(testUnescapingHelper(L"%0g", L"%0g"));
+ ASSERT_TRUE(testUnescapingHelper(L"%G0", L"%G0"));
+
+ // No double decoding
+ ASSERT_TRUE(testUnescapingHelper(L"%2520", L"%20"));
+
+ // Decoding of '+'
+ ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc+def", PLUS_DONT_TOUCH));
+ ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc def", PLUS_TO_SPACE));
+
+ // Line break conversion
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+}
+
+namespace {
+ bool testAddBaseHelper(const wchar_t * base, const wchar_t * rel, const wchar_t * expectedResult, bool backward_compatibility = false) {
+ UriParserStateW stateW;
+
+ // Base
+ UriUriW baseUri;
+ stateW.uri = &baseUri;
+ int res = uriParseUriW(&stateW, base);
+ if (res != 0) {
+ uriFreeUriMembersW(&baseUri);
+ return false;
+ }
+
+ // Rel
+ UriUriW relUri;
+ stateW.uri = &relUri;
+ res = uriParseUriW(&stateW, rel);
+ if (res != 0) {
+ uriFreeUriMembersW(&baseUri);
+ uriFreeUriMembersW(&relUri);
+ return false;
+ }
+
+ // Expected result
+ UriUriW expectedUri;
+ stateW.uri = &expectedUri;
+ res = uriParseUriW(&stateW, expectedResult);
+ if (res != 0) {
+ uriFreeUriMembersW(&baseUri);
+ uriFreeUriMembersW(&relUri);
+ uriFreeUriMembersW(&expectedUri);
+ return false;
+ }
+
+ // Transform
+ UriUriW transformedUri;
+ if (backward_compatibility) {
+ res = uriAddBaseUriExW(&transformedUri, &relUri, &baseUri, URI_RESOLVE_IDENTICAL_SCHEME_COMPAT);
+ } else {
+ res = uriAddBaseUriW(&transformedUri, &relUri, &baseUri);
+ }
+
+ if (res != 0) {
+ uriFreeUriMembersW(&baseUri);
+ uriFreeUriMembersW(&relUri);
+ uriFreeUriMembersW(&expectedUri);
+ uriFreeUriMembersW(&transformedUri);
+ return false;
+ }
+
+ const bool equal = (URI_TRUE == uriEqualsUriW(&transformedUri, &expectedUri));
+ if (!equal) {
+ wchar_t transformedUriText[1024 * 8];
+ wchar_t expectedUriText[1024 * 8];
+ uriToStringW(transformedUriText, &transformedUri, 1024 * 8, NULL);
+ uriToStringW(expectedUriText, &expectedUri, 1024 * 8, NULL);
+#ifdef HAVE_WPRINTF
+ wprintf(L"\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", expectedUriText, transformedUriText);
+#endif
+ }
+
+ uriFreeUriMembersW(&baseUri);
+ uriFreeUriMembersW(&relUri);
+ uriFreeUriMembersW(&expectedUri);
+ uriFreeUriMembersW(&transformedUri);
+ return equal;
+ }
+} // namespace
+
+TEST(UriSuite, TestTrailingSlash) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ // 0 3 01
+ const char * const input = "abc" "/";
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.pathHead->text.first == input);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 3);
+ ASSERT_TRUE(uriA.pathHead->next->text.first == uriA.pathHead->next->text.afterLast);
+ ASSERT_TRUE(uriA.pathHead->next->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
+ uriFreeUriMembersA(&uriA);
+}
+
+TEST(UriSuite, TestAddBase) {
+ // 5.4.1. Normal Examples
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g:h", L"g:h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g", L"http://a/b/c/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g", L"http://a/b/c/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/", L"http://a/b/c/g/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"//g", L"http://g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"?y", L"http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y", L"http://a/b/c/g?y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"#s", L"http://a/b/c/d;p?q#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s", L"http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y#s", L"http://a/b/c/g?y#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L";x", L"http://a/b/c/;x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x", L"http://a/b/c/g;x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x?y#s", L"http://a/b/c/g;x?y#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"", L"http://a/b/c/d;p?q"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".", L"http://a/b/c/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./", L"http://a/b/c/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..", L"http://a/b/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../", L"http://a/b/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../g", L"http://a/b/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../..", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../g", L"http://a/g"));
+
+ // 5.4.2. Abnormal Examples
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/./g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g.", L"http://a/b/c/g."));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".g", L"http://a/b/c/.g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g..", L"http://a/b/c/g.."));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..g", L"http://a/b/c/..g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./../g", L"http://a/b/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g/.", L"http://a/b/c/g/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/./h", L"http://a/b/c/g/h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/../h", L"http://a/b/c/h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/./y", L"http://a/b/c/g;x=1/y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/../y", L"http://a/b/c/y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/./x", L"http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/../x", L"http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/./x", L"http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/../x", L"http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g"));
+
+ // Backward compatibility (feature request #4, RFC3986 5.4.2)
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g", false));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http://a/b/c/g", true));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g?q#f", L"http://a/b/c/g?q#f", true));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"other:g?q#f", L"other:g?q#f", true));
+
+ // Bug related to absolutePath flag set despite presence of host
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g/", L"http://a/g/"));
// GitHub issue #92
EXPECT_TRUE(testAddBaseHelper(L"http://a/b/c/../d;p?q", L"../..", L"http://a/"));
@@ -1111,385 +1111,385 @@ TEST(UriSuite, TestAddBase) {
EXPECT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../..", L"http://a/"));
EXPECT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../", L"http://a/"));
-}
-
-namespace {
- bool testToStringHelper(const wchar_t * text) {
- // Parse
- UriParserStateW state;
- UriUriW uri;
- state.uri = &uri;
- int res = uriParseUriW(&state, text);
- if (res != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- // Back to string, _huge_ limit
- wchar_t shouldbeTheSame[1024 * 8];
- res = uriToStringW(shouldbeTheSame, &uri, 1024 * 8, NULL);
- if (res != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- // Compare
- bool equals = (0 == wcscmp(shouldbeTheSame, text));
- if (!equals) {
-#ifdef HAVE_WPRINTF
- wprintf(L"\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", text, shouldbeTheSame);
-#endif
- }
-
- // Back to string, _exact_ limit
- const int len = static_cast<int>(wcslen(text));
- int charsWritten;
- res = uriToStringW(shouldbeTheSame, &uri, len + 1, &charsWritten);
- if ((res != 0) || (charsWritten != len + 1)) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- // Back to string, _too small_ limit
- res = uriToStringW(shouldbeTheSame, &uri, len, &charsWritten);
- if ((res == 0) || (charsWritten >= len + 1)) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- uriFreeUriMembersW(&uri);
- return equals;
- }
-} // namespace
-
-TEST(UriSuite, TestToString) {
- // Scheme
- ASSERT_TRUE(testToStringHelper(L"ftp://localhost/"));
- // UserInfo
- ASSERT_TRUE(testToStringHelper(L"http://user:pass@localhost/"));
- // IPv4
- ASSERT_TRUE(testToStringHelper(L"http://123.0.1.255/"));
- // IPv6
- ASSERT_TRUE(testToStringHelper(L"http://[abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd]/"));
- // IPvFuture
- ASSERT_TRUE(testToStringHelper(L"http://[vA.123456]/"));
- // Port
- ASSERT_TRUE(testToStringHelper(L"http://example.com:123/"));
- // Path
- ASSERT_TRUE(testToStringHelper(L"http://example.com"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def/"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com//"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/./.."));
- // Query
- ASSERT_TRUE(testToStringHelper(L"http://example.com/?abc"));
- // Fragment
- ASSERT_TRUE(testToStringHelper(L"http://example.com/#abc"));
- ASSERT_TRUE(testToStringHelper(L"http://example.com/?def#abc"));
-
- // Relative
- ASSERT_TRUE(testToStringHelper(L"a"));
- ASSERT_TRUE(testToStringHelper(L"a/"));
- ASSERT_TRUE(testToStringHelper(L"/a"));
- ASSERT_TRUE(testToStringHelper(L"/a/"));
- ASSERT_TRUE(testToStringHelper(L"abc"));
- ASSERT_TRUE(testToStringHelper(L"abc/"));
- ASSERT_TRUE(testToStringHelper(L"/abc"));
- ASSERT_TRUE(testToStringHelper(L"/abc/"));
- ASSERT_TRUE(testToStringHelper(L"a/def"));
- ASSERT_TRUE(testToStringHelper(L"a/def/"));
- ASSERT_TRUE(testToStringHelper(L"/a/def"));
- ASSERT_TRUE(testToStringHelper(L"/a/def/"));
- ASSERT_TRUE(testToStringHelper(L"abc/def"));
- ASSERT_TRUE(testToStringHelper(L"abc/def/"));
- ASSERT_TRUE(testToStringHelper(L"/abc/def"));
- ASSERT_TRUE(testToStringHelper(L"/abc/def/"));
- ASSERT_TRUE(testToStringHelper(L"/"));
- ASSERT_TRUE(testToStringHelper(L"//a/"));
- ASSERT_TRUE(testToStringHelper(L"."));
- ASSERT_TRUE(testToStringHelper(L"./"));
- ASSERT_TRUE(testToStringHelper(L"/."));
- ASSERT_TRUE(testToStringHelper(L"/./"));
- ASSERT_TRUE(testToStringHelper(L""));
- ASSERT_TRUE(testToStringHelper(L"./abc/def"));
- ASSERT_TRUE(testToStringHelper(L"?query"));
- ASSERT_TRUE(testToStringHelper(L"#fragment"));
- ASSERT_TRUE(testToStringHelper(L"?query#fragment"));
-
- // Tests for bugs from the past
- ASSERT_TRUE(testToStringHelper(L"f:/.//g"));
-}
-
-TEST(UriSuite, TestToStringBug1950126) {
- UriParserStateW state;
- UriUriW uriOne;
- UriUriW uriTwo;
- const wchar_t * const uriOneString = L"http://e.com/";
- const wchar_t * const uriTwoString = L"http://e.com";
- state.uri = &uriOne;
- ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriOneString));
- state.uri = &uriTwo;
- ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriTwoString));
- ASSERT_TRUE(URI_FALSE == uriEqualsUriW(&uriOne, &uriTwo));
- uriFreeUriMembersW(&uriOne);
- uriFreeUriMembersW(&uriTwo);
-
- ASSERT_TRUE(testToStringHelper(uriOneString));
- ASSERT_TRUE(testToStringHelper(uriTwoString));
-}
-
-namespace {
- bool testToStringCharsRequiredHelper(const wchar_t * text) {
- // Parse
- UriParserStateW state;
- UriUriW uri;
- state.uri = &uri;
- int res = uriParseUriW(&state, text);
- if (res != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- // Required space?
- int charsRequired;
- if (uriToStringCharsRequiredW(&uri, &charsRequired) != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- EXPECT_EQ(charsRequired, wcslen(text));
-
- // Minimum
- wchar_t * buffer = new wchar_t[charsRequired + 1];
- if (uriToStringW(buffer, &uri, charsRequired + 1, NULL) != 0) {
- uriFreeUriMembersW(&uri);
- delete [] buffer;
- return false;
- }
-
- // One less than minimum
- if (uriToStringW(buffer, &uri, charsRequired, NULL) == 0) {
- uriFreeUriMembersW(&uri);
- delete [] buffer;
- return false;
- }
-
- uriFreeUriMembersW(&uri);
- delete [] buffer;
- return true;
- }
-} // namespace
-
-TEST(UriSuite, TestToStringCharsRequired) {
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://12.1.1.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://123.1.1.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.12.1.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.123.1.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.12.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.123.1/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.12/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.123/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com:80/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://user:pass@www.example.com/"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/index.html"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/#def"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc#def"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"/test"));
- EXPECT_TRUE(testToStringCharsRequiredHelper(L"test"));
-}
-
-namespace {
- bool testNormalizeMaskHelper(const wchar_t * uriText, unsigned int expectedMask) {
- UriParserStateW state;
- UriUriW uri;
- state.uri = &uri;
- int res = uriParseUriW(&state, uriText);
- if (res != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- const unsigned int maskBefore = uriNormalizeSyntaxMaskRequiredW(&uri);
- if (maskBefore != expectedMask) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- res = uriNormalizeSyntaxW(&uri);
- if (res != 0) {
- uriFreeUriMembersW(&uri);
- return false;
- }
-
- const unsigned int maskAfter = uriNormalizeSyntaxMaskRequiredW(&uri);
- uriFreeUriMembersW(&uri);
-
- // Second call should be no problem
- uriFreeUriMembersW(&uri);
-
- return (maskAfter == URI_NORMALIZED);
- }
-} // namespace
-
-TEST(UriSuite, TestNormalizeSyntaxMaskRequired) {
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/", URI_NORMALIZED));
- ASSERT_TRUE(testNormalizeMaskHelper(L"httP://localhost/", URI_NORMALIZE_SCHEME));
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://%0d@localhost/", URI_NORMALIZE_USER_INFO));
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhosT/", URI_NORMALIZE_HOST));
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/./abc", URI_NORMALIZE_PATH));
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/?AB%43", URI_NORMALIZE_QUERY));
- ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/#AB%43", URI_NORMALIZE_FRAGMENT));
-}
-
-namespace {
- bool testNormalizeSyntaxHelper(const wchar_t * uriText, const wchar_t * expectedNormalized,
- unsigned int mask = static_cast<unsigned int>(-1)) {
- UriParserStateW stateW;
- int res;
-
- UriUriW testUri;
- stateW.uri = &testUri;
- res = uriParseUriW(&stateW, uriText);
- if (res != 0) {
- uriFreeUriMembersW(&testUri);
- return false;
- }
-
- // Expected result
- UriUriW expectedUri;
- stateW.uri = &expectedUri;
- res = uriParseUriW(&stateW, expectedNormalized);
- if (res != 0) {
- uriFreeUriMembersW(&testUri);
- uriFreeUriMembersW(&expectedUri);
- return false;
- }
-
- // First run
- res = uriNormalizeSyntaxExW(&testUri, mask);
- if (res != 0) {
- uriFreeUriMembersW(&testUri);
- uriFreeUriMembersW(&expectedUri);
- return false;
- }
-
- bool equalAfter = (URI_TRUE == uriEqualsUriW(&testUri, &expectedUri));
-
- // Second run
- res = uriNormalizeSyntaxExW(&testUri, mask);
- if (res != 0) {
- uriFreeUriMembersW(&testUri);
- uriFreeUriMembersW(&expectedUri);
- return false;
- }
-
- equalAfter = equalAfter
- && (URI_TRUE == uriEqualsUriW(&testUri, &expectedUri));
-
- uriFreeUriMembersW(&testUri);
- uriFreeUriMembersW(&expectedUri);
- return equalAfter;
- }
-} // namespace
-
-TEST(UriSuite, TestNormalizeSyntax) {
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"eXAMPLE://a/./b/../b/%63/%7bfoo%7d",
- L"example://a/b/c/%7Bfoo%7D"));
-
- // Testcase by Adrian Manrique
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"http://examp%4Ce.com/",
- L"http://example.com/"));
-
- // Testcase by Adrian Manrique
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"http://example.com/a/b/%2E%2E/",
- L"http://example.com/a/"));
-
- // Reported by Adrian Manrique
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"http://user:pass@SOMEHOST.COM:123",
- L"http://user:pass@somehost.com:123"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://a:b@HOST:123/./1/2/../%41?abc#def",
- L"http://a:b@host:123/1/A?abc#def"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"../../abc",
- L"../../abc"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"../../abc/..",
- L"../../"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"../../abc/../def",
- L"../../def"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"abc/..",
- L""));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"abc/../",
- L""));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"../../abc/./def",
- L"../../abc/def"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"./def",
- L"def"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"def/.",
- L"def/"));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"./abc:def",
- L"./abc:def"));
-}
-
-TEST(UriSuite, TestNormalizeSyntaxComponents) {
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"http://%41@EXAMPLE.ORG/../a?%41#%41",
- URI_NORMALIZE_SCHEME));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"HTTP://A@EXAMPLE.ORG/../a?%41#%41",
- URI_NORMALIZE_USER_INFO));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"HTTP://%41@example.org/../a?%41#%41",
- URI_NORMALIZE_HOST));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"HTTP://%41@EXAMPLE.ORG/a?%41#%41",
- URI_NORMALIZE_PATH));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"HTTP://%41@EXAMPLE.ORG/../a?A#%41",
- URI_NORMALIZE_QUERY));
-
- ASSERT_TRUE(testNormalizeSyntaxHelper(
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
- L"HTTP://%41@EXAMPLE.ORG/../a?%41#A",
- URI_NORMALIZE_FRAGMENT));
-}
-
+}
+
+namespace {
+ bool testToStringHelper(const wchar_t * text) {
+ // Parse
+ UriParserStateW state;
+ UriUriW uri;
+ state.uri = &uri;
+ int res = uriParseUriW(&state, text);
+ if (res != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ // Back to string, _huge_ limit
+ wchar_t shouldbeTheSame[1024 * 8];
+ res = uriToStringW(shouldbeTheSame, &uri, 1024 * 8, NULL);
+ if (res != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ // Compare
+ bool equals = (0 == wcscmp(shouldbeTheSame, text));
+ if (!equals) {
+#ifdef HAVE_WPRINTF
+ wprintf(L"\n\n\nExpected: \"%s\"\nReceived: \"%s\"\n\n\n", text, shouldbeTheSame);
+#endif
+ }
+
+ // Back to string, _exact_ limit
+ const int len = static_cast<int>(wcslen(text));
+ int charsWritten;
+ res = uriToStringW(shouldbeTheSame, &uri, len + 1, &charsWritten);
+ if ((res != 0) || (charsWritten != len + 1)) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ // Back to string, _too small_ limit
+ res = uriToStringW(shouldbeTheSame, &uri, len, &charsWritten);
+ if ((res == 0) || (charsWritten >= len + 1)) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ uriFreeUriMembersW(&uri);
+ return equals;
+ }
+} // namespace
+
+TEST(UriSuite, TestToString) {
+ // Scheme
+ ASSERT_TRUE(testToStringHelper(L"ftp://localhost/"));
+ // UserInfo
+ ASSERT_TRUE(testToStringHelper(L"http://user:pass@localhost/"));
+ // IPv4
+ ASSERT_TRUE(testToStringHelper(L"http://123.0.1.255/"));
+ // IPv6
+ ASSERT_TRUE(testToStringHelper(L"http://[abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd]/"));
+ // IPvFuture
+ ASSERT_TRUE(testToStringHelper(L"http://[vA.123456]/"));
+ // Port
+ ASSERT_TRUE(testToStringHelper(L"http://example.com:123/"));
+ // Path
+ ASSERT_TRUE(testToStringHelper(L"http://example.com"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com//"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/./.."));
+ // Query
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/?abc"));
+ // Fragment
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/#abc"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/?def#abc"));
+
+ // Relative
+ ASSERT_TRUE(testToStringHelper(L"a"));
+ ASSERT_TRUE(testToStringHelper(L"a/"));
+ ASSERT_TRUE(testToStringHelper(L"/a"));
+ ASSERT_TRUE(testToStringHelper(L"/a/"));
+ ASSERT_TRUE(testToStringHelper(L"abc"));
+ ASSERT_TRUE(testToStringHelper(L"abc/"));
+ ASSERT_TRUE(testToStringHelper(L"/abc"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/"));
+ ASSERT_TRUE(testToStringHelper(L"a/def"));
+ ASSERT_TRUE(testToStringHelper(L"a/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/a/def"));
+ ASSERT_TRUE(testToStringHelper(L"/a/def/"));
+ ASSERT_TRUE(testToStringHelper(L"abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/"));
+ ASSERT_TRUE(testToStringHelper(L"//a/"));
+ ASSERT_TRUE(testToStringHelper(L"."));
+ ASSERT_TRUE(testToStringHelper(L"./"));
+ ASSERT_TRUE(testToStringHelper(L"/."));
+ ASSERT_TRUE(testToStringHelper(L"/./"));
+ ASSERT_TRUE(testToStringHelper(L""));
+ ASSERT_TRUE(testToStringHelper(L"./abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"?query"));
+ ASSERT_TRUE(testToStringHelper(L"#fragment"));
+ ASSERT_TRUE(testToStringHelper(L"?query#fragment"));
+
+ // Tests for bugs from the past
+ ASSERT_TRUE(testToStringHelper(L"f:/.//g"));
+}
+
+TEST(UriSuite, TestToStringBug1950126) {
+ UriParserStateW state;
+ UriUriW uriOne;
+ UriUriW uriTwo;
+ const wchar_t * const uriOneString = L"http://e.com/";
+ const wchar_t * const uriTwoString = L"http://e.com";
+ state.uri = &uriOne;
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriOneString));
+ state.uri = &uriTwo;
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriTwoString));
+ ASSERT_TRUE(URI_FALSE == uriEqualsUriW(&uriOne, &uriTwo));
+ uriFreeUriMembersW(&uriOne);
+ uriFreeUriMembersW(&uriTwo);
+
+ ASSERT_TRUE(testToStringHelper(uriOneString));
+ ASSERT_TRUE(testToStringHelper(uriTwoString));
+}
+
+namespace {
+ bool testToStringCharsRequiredHelper(const wchar_t * text) {
+ // Parse
+ UriParserStateW state;
+ UriUriW uri;
+ state.uri = &uri;
+ int res = uriParseUriW(&state, text);
+ if (res != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ // Required space?
+ int charsRequired;
+ if (uriToStringCharsRequiredW(&uri, &charsRequired) != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ EXPECT_EQ(charsRequired, wcslen(text));
+
+ // Minimum
+ wchar_t * buffer = new wchar_t[charsRequired + 1];
+ if (uriToStringW(buffer, &uri, charsRequired + 1, NULL) != 0) {
+ uriFreeUriMembersW(&uri);
+ delete [] buffer;
+ return false;
+ }
+
+ // One less than minimum
+ if (uriToStringW(buffer, &uri, charsRequired, NULL) == 0) {
+ uriFreeUriMembersW(&uri);
+ delete [] buffer;
+ return false;
+ }
+
+ uriFreeUriMembersW(&uri);
+ delete [] buffer;
+ return true;
+ }
+} // namespace
+
+TEST(UriSuite, TestToStringCharsRequired) {
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://12.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://123.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.12.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.123.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.12.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.123.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.12/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.123/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com:80/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://user:pass@www.example.com/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/index.html"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/#def"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc#def"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"/test"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"test"));
+}
+
+namespace {
+ bool testNormalizeMaskHelper(const wchar_t * uriText, unsigned int expectedMask) {
+ UriParserStateW state;
+ UriUriW uri;
+ state.uri = &uri;
+ int res = uriParseUriW(&state, uriText);
+ if (res != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ const unsigned int maskBefore = uriNormalizeSyntaxMaskRequiredW(&uri);
+ if (maskBefore != expectedMask) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ res = uriNormalizeSyntaxW(&uri);
+ if (res != 0) {
+ uriFreeUriMembersW(&uri);
+ return false;
+ }
+
+ const unsigned int maskAfter = uriNormalizeSyntaxMaskRequiredW(&uri);
+ uriFreeUriMembersW(&uri);
+
+ // Second call should be no problem
+ uriFreeUriMembersW(&uri);
+
+ return (maskAfter == URI_NORMALIZED);
+ }
+} // namespace
+
+TEST(UriSuite, TestNormalizeSyntaxMaskRequired) {
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/", URI_NORMALIZED));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"httP://localhost/", URI_NORMALIZE_SCHEME));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://%0d@localhost/", URI_NORMALIZE_USER_INFO));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhosT/", URI_NORMALIZE_HOST));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/./abc", URI_NORMALIZE_PATH));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/?AB%43", URI_NORMALIZE_QUERY));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/#AB%43", URI_NORMALIZE_FRAGMENT));
+}
+
+namespace {
+ bool testNormalizeSyntaxHelper(const wchar_t * uriText, const wchar_t * expectedNormalized,
+ unsigned int mask = static_cast<unsigned int>(-1)) {
+ UriParserStateW stateW;
+ int res;
+
+ UriUriW testUri;
+ stateW.uri = &testUri;
+ res = uriParseUriW(&stateW, uriText);
+ if (res != 0) {
+ uriFreeUriMembersW(&testUri);
+ return false;
+ }
+
+ // Expected result
+ UriUriW expectedUri;
+ stateW.uri = &expectedUri;
+ res = uriParseUriW(&stateW, expectedNormalized);
+ if (res != 0) {
+ uriFreeUriMembersW(&testUri);
+ uriFreeUriMembersW(&expectedUri);
+ return false;
+ }
+
+ // First run
+ res = uriNormalizeSyntaxExW(&testUri, mask);
+ if (res != 0) {
+ uriFreeUriMembersW(&testUri);
+ uriFreeUriMembersW(&expectedUri);
+ return false;
+ }
+
+ bool equalAfter = (URI_TRUE == uriEqualsUriW(&testUri, &expectedUri));
+
+ // Second run
+ res = uriNormalizeSyntaxExW(&testUri, mask);
+ if (res != 0) {
+ uriFreeUriMembersW(&testUri);
+ uriFreeUriMembersW(&expectedUri);
+ return false;
+ }
+
+ equalAfter = equalAfter
+ && (URI_TRUE == uriEqualsUriW(&testUri, &expectedUri));
+
+ uriFreeUriMembersW(&testUri);
+ uriFreeUriMembersW(&expectedUri);
+ return equalAfter;
+ }
+} // namespace
+
+TEST(UriSuite, TestNormalizeSyntax) {
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"eXAMPLE://a/./b/../b/%63/%7bfoo%7d",
+ L"example://a/b/c/%7Bfoo%7D"));
+
+ // Testcase by Adrian Manrique
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"http://examp%4Ce.com/",
+ L"http://example.com/"));
+
+ // Testcase by Adrian Manrique
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"http://example.com/a/b/%2E%2E/",
+ L"http://example.com/a/"));
+
+ // Reported by Adrian Manrique
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"http://user:pass@SOMEHOST.COM:123",
+ L"http://user:pass@somehost.com:123"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://a:b@HOST:123/./1/2/../%41?abc#def",
+ L"http://a:b@host:123/1/A?abc#def"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"../../abc",
+ L"../../abc"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"../../abc/..",
+ L"../../"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"../../abc/../def",
+ L"../../def"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"abc/..",
+ L""));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"abc/../",
+ L""));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"../../abc/./def",
+ L"../../abc/def"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"./def",
+ L"def"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"def/.",
+ L"def/"));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"./abc:def",
+ L"./abc:def"));
+}
+
+TEST(UriSuite, TestNormalizeSyntaxComponents) {
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"http://%41@EXAMPLE.ORG/../a?%41#%41",
+ URI_NORMALIZE_SCHEME));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"HTTP://A@EXAMPLE.ORG/../a?%41#%41",
+ URI_NORMALIZE_USER_INFO));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"HTTP://%41@example.org/../a?%41#%41",
+ URI_NORMALIZE_HOST));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"HTTP://%41@EXAMPLE.ORG/a?%41#%41",
+ URI_NORMALIZE_PATH));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"HTTP://%41@EXAMPLE.ORG/../a?A#%41",
+ URI_NORMALIZE_QUERY));
+
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
+ L"HTTP://%41@EXAMPLE.ORG/../a?%41#A",
+ URI_NORMALIZE_FRAGMENT));
+}
+
TEST(UriSuite, TestNormalizeSyntaxPath) {
// These are from GitHub issue #92
EXPECT_TRUE(testNormalizeSyntaxHelper(
@@ -1532,690 +1532,690 @@ TEST(UriSuite, TestNormalizeSyntaxPath) {
URI_NORMALIZE_PATH));
}
-TEST(UriSuite, TestNormalizeCrashBug20080224) {
- UriParserStateW stateW;
- int res;
- UriUriW testUri;
- stateW.uri = &testUri;
-
- res = uriParseUriW(&stateW, L"http://example.org/abc//../def");
- ASSERT_TRUE(res == 0);
-
- // First call will make us owner of copied memory
- res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_SCHEME);
- ASSERT_TRUE(res == 0);
- res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_HOST);
- ASSERT_TRUE(res == 0);
-
- // Frees empty path segment -> crash
- res = uriNormalizeSyntaxW(&testUri);
- ASSERT_TRUE(res == 0);
-
- uriFreeUriMembersW(&testUri);
-}
-
-namespace {
- void testFilenameUriConversionHelper(const wchar_t * filename,
- const wchar_t * uriString, bool forUnix,
- const wchar_t * expectedUriString = NULL) {
- const int prefixLen = forUnix ? 7 : 8;
- if (! expectedUriString) {
- expectedUriString = uriString;
- }
-
- // Filename to URI string
- const size_t uriBufferLen = prefixLen + 3 * wcslen(filename) + 1;
- wchar_t * uriBuffer = new wchar_t[uriBufferLen];
- if (forUnix) {
- uriUnixFilenameToUriStringW(filename, uriBuffer);
- } else {
- uriWindowsFilenameToUriStringW(filename, uriBuffer);
- }
-#ifdef HAVE_WPRINTF
- // wprintf(L"1 [%s][%s]\n", uriBuffer, expectedUriString);
-#endif
- ASSERT_TRUE(!wcscmp(uriBuffer, expectedUriString));
- delete [] uriBuffer;
-
- // URI string to filename
- const size_t filenameBufferLen = wcslen(uriString) + 1;
- wchar_t * filenameBuffer = new wchar_t[filenameBufferLen];
- if (forUnix) {
- uriUriStringToUnixFilenameW(uriString, filenameBuffer);
- } else {
- uriUriStringToWindowsFilenameW(uriString, filenameBuffer);
- }
-#ifdef HAVE_WPRINTF
- // wprintf(L"2 [%s][%s]\n", filenameBuffer, filename);
-#endif
- ASSERT_TRUE(!wcscmp(filenameBuffer, filename));
- delete [] filenameBuffer;
- }
-} // namespace
-
-TEST(UriSuite, TestFilenameUriConversion) {
- const bool FOR_UNIX = true;
- const bool FOR_WINDOWS = false;
- testFilenameUriConversionHelper(L"/bin/bash", L"file:///bin/bash", FOR_UNIX);
- testFilenameUriConversionHelper(L"/bin/bash", L"file:/bin/bash", FOR_UNIX, L"file:///bin/bash");
- testFilenameUriConversionHelper(L"./configure", L"./configure", FOR_UNIX);
-
- testFilenameUriConversionHelper(L"E:\\Documents and Settings", L"file:///E:/Documents%20and%20Settings", FOR_WINDOWS);
- testFilenameUriConversionHelper(L"c:\\path\\to\\file.txt", L"file:c:/path/to/file.txt", FOR_WINDOWS, L"file:///c:/path/to/file.txt");
-
- testFilenameUriConversionHelper(L".\\Readme.txt", L"./Readme.txt", FOR_WINDOWS);
-
- testFilenameUriConversionHelper(L"index.htm", L"index.htm", FOR_WINDOWS);
- testFilenameUriConversionHelper(L"index.htm", L"index.htm", FOR_UNIX);
-
- testFilenameUriConversionHelper(L"abc def", L"abc%20def", FOR_WINDOWS);
- testFilenameUriConversionHelper(L"abc def", L"abc%20def", FOR_UNIX);
-
- testFilenameUriConversionHelper(L"\\\\Server01\\user\\docs\\Letter.txt", L"file://Server01/user/docs/Letter.txt", FOR_WINDOWS);
-}
-
-TEST(UriSuite, TestCrashFreeUriMembersBug20080116) {
- // Testcase by Adrian Manrique
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
- uriParseUriA(&state, "http://test/?");
- uriNormalizeSyntaxA(&uri);
- uriFreeUriMembersA(&uri);
-
- ASSERT_TRUE(true);
-}
-
-namespace {
- void helperTestQueryString(char const * uriString, int pairsExpected);
-}
-
-TEST(UriSuite, TestCrashReport2418192) {
- // Testcase by Harvey Vrsalovic
- helperTestQueryString("http://svcs.cnn.com/weather/wrapper.jsp?&csiID=csi1", 1);
-}
-
-TEST(UriSuite, TestPervertedQueryString) {
- helperTestQueryString("http://example.org/?&&=&&&=&&&&==&===&====", 5);
-}
-
-TEST(UriSuite, TestQueryStringEndingInEqualSignNonBug32) {
- const char * queryString = "firstname=sdsd&lastname=";
-
- UriQueryListA * queryList = NULL;
- int itemCount = 0;
- const int res = uriDissectQueryMallocA(&queryList, &itemCount,
- queryString, queryString + strlen(queryString));
-
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(itemCount == 2);
- ASSERT_TRUE(queryList != NULL);
- ASSERT_TRUE(strcmp(queryList->key, "firstname") == 0);
- ASSERT_TRUE(strcmp(queryList->value, "sdsd") == 0);
- ASSERT_TRUE(strcmp(queryList->next->key, "lastname") == 0);
- ASSERT_TRUE(strcmp(queryList->next->value, "") == 0);
- ASSERT_TRUE(queryList->next->next == NULL);
-
- uriFreeQueryListA(queryList);
-}
-
-namespace {
- void helperTestQueryString(char const * uriString, int pairsExpected) {
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
- int res = uriParseUriA(&state, uriString);
- ASSERT_TRUE(res == URI_SUCCESS);
-
- UriQueryListA * queryList = NULL;
- int itemCount = 0;
-
- res = uriDissectQueryMallocA(&queryList, &itemCount,
- uri.query.first, uri.query.afterLast);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(queryList != NULL);
- ASSERT_TRUE(itemCount == pairsExpected);
- uriFreeQueryListA(queryList);
- uriFreeUriMembersA(&uri);
- }
-} // namespace
-
-TEST(UriSuite, TestCrashMakeOwnerBug20080207) {
- // Testcase by Adrian Manrique
- UriParserStateA state;
- UriUriA sourceUri;
- state.uri = &sourceUri;
- const char * const sourceUriString = "http://user:pass@somehost.com:80/";
- if (uriParseUriA(&state, sourceUriString) != 0) {
- ASSERT_TRUE(false);
- }
- if (uriNormalizeSyntaxA(&sourceUri) != 0) {
- ASSERT_TRUE(false);
- }
- uriFreeUriMembersA(&sourceUri);
- ASSERT_TRUE(true);
-}
-
-namespace {
- void testQueryListHelper(const wchar_t * input, int expectedItemCount) {
- int res;
-
- UriBool spacePlusConversion = URI_TRUE;
- UriBool normalizeBreaks = URI_FALSE;
- UriBreakConversion breakConversion = URI_BR_DONT_TOUCH;
-
- int itemCount;
- UriQueryListW * queryList;
- res = uriDissectQueryMallocExW(&queryList, &itemCount,
- input, input + wcslen(input), spacePlusConversion, breakConversion);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(itemCount == expectedItemCount);
- ASSERT_TRUE((queryList == NULL) == (expectedItemCount == 0));
-
- if (expectedItemCount != 0) {
- // First
- int charsRequired;
- res = uriComposeQueryCharsRequiredExW(queryList, &charsRequired, spacePlusConversion,
- normalizeBreaks);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(charsRequired >= (int)wcslen(input));
-
- wchar_t * recomposed = new wchar_t[charsRequired + 1];
- int charsWritten;
- res = uriComposeQueryExW(recomposed, queryList, charsRequired + 1,
- &charsWritten, spacePlusConversion, normalizeBreaks);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(charsWritten <= charsRequired);
- ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
- ASSERT_TRUE(!wcscmp(input, recomposed));
- delete [] recomposed;
-
- recomposed = NULL;
- res = uriComposeQueryMallocW(&recomposed, queryList);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(recomposed != NULL);
- ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
- ASSERT_TRUE(!wcscmp(input, recomposed));
- free(recomposed);
- }
-
- uriFreeQueryListW(queryList);
- }
-} // namespace
-
-TEST(UriSuite, QueryList) {
- testQueryListHelper(L"one=ONE&two=TWO", 2);
- testQueryListHelper(L"one=ONE&two=&three=THREE", 3);
- testQueryListHelper(L"one=ONE&two&three=THREE", 3);
- testQueryListHelper(L"one=ONE", 1);
- testQueryListHelper(L"one", 1);
- testQueryListHelper(L"", 0);
-}
-
-namespace {
- void testQueryListPairHelper(const char * pair, const char * unescapedKey,
- const char * unescapedValue, const char * fixed = NULL) {
- int res;
- UriQueryListA * queryList;
- int itemCount;
-
- res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(queryList != NULL);
- ASSERT_TRUE(itemCount == 1);
- ASSERT_TRUE(!strcmp(queryList->key, unescapedKey));
- ASSERT_TRUE(!strcmp(queryList->value, unescapedValue));
-
- char * recomposed;
- res = uriComposeQueryMallocA(&recomposed, queryList);
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(recomposed != NULL);
- ASSERT_TRUE(!strcmp(recomposed, (fixed != NULL) ? fixed : pair));
- free(recomposed);
- uriFreeQueryListA(queryList);
- }
-} // namespace
-
-TEST(UriSuite, TestQueryListPair) {
- testQueryListPairHelper("one+two+%26+three=%2B", "one two & three", "+");
- testQueryListPairHelper("one=two=three", "one", "two=three", "one=two%3Dthree");
- testQueryListPairHelper("one=two=three=four", "one", "two=three=four", "one=two%3Dthree%3Dfour");
-}
-
-TEST(UriSuite, TestQueryDissectionBug3590761) {
- int res;
- UriQueryListA * queryList;
- int itemCount;
- const char * const pair = "q=hello&x=&y=";
-
- res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
- ASSERT_TRUE(res == URI_SUCCESS);
- ASSERT_TRUE(queryList != NULL);
- ASSERT_TRUE(itemCount == 3);
-
- ASSERT_TRUE(!strcmp(queryList->key, "q"));
- ASSERT_TRUE(!strcmp(queryList->value, "hello"));
-
- ASSERT_TRUE(!strcmp(queryList->next->key, "x"));
- ASSERT_TRUE(!strcmp(queryList->next->value, ""));
-
- ASSERT_TRUE(!strcmp(queryList->next->next->key, "y"));
- ASSERT_TRUE(!strcmp(queryList->next->next->value, ""));
-
- ASSERT_TRUE(! queryList->next->next->next);
-
- uriFreeQueryListA(queryList);
-}
-
-TEST(UriSuite, TestQueryCompositionMathCalc) {
- UriQueryListA second = { /*.key =*/ "k2", /*.value =*/ "v2", /*.next =*/ NULL };
- UriQueryListA first = { /*.key =*/ "k1", /*.value =*/ "v1", /*.next =*/ &second };
-
- int charsRequired;
- ASSERT_TRUE(uriComposeQueryCharsRequiredA(&first, &charsRequired)
- == URI_SUCCESS);
-
- const int FACTOR = 6; /* due to escaping with normalizeBreaks */
- ASSERT_TRUE((unsigned)charsRequired ==
- FACTOR * strlen(first.key) + 1 + FACTOR * strlen(first.value)
- + 1
- + FACTOR * strlen(second.key) + 1 + FACTOR * strlen(second.value)
- );
-}
-
-TEST(UriSuite, TestQueryCompositionMathWriteGoogleAutofuzz113244572) {
- UriQueryListA second = { /*.key =*/ "\x11", /*.value =*/ NULL, /*.next =*/ NULL };
- UriQueryListA first = { /*.key =*/ "\x01", /*.value =*/ "\x02", /*.next =*/ &second };
-
- const UriBool spaceToPlus = URI_TRUE;
- const UriBool normalizeBreaks = URI_FALSE; /* for factor 3 but 6 */
-
- const int charsRequired = (3 + 1 + 3) + 1 + (3);
-
- {
- // Minimum space to hold everything fine
- const char * const expected = "%01=%02" "&" "%11";
- char dest[charsRequired + 1];
- int charsWritten;
- ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
- &charsWritten, spaceToPlus, normalizeBreaks)
- == URI_SUCCESS);
- ASSERT_TRUE(! strcmp(dest, expected));
- ASSERT_TRUE(charsWritten == strlen(expected) + 1);
- }
-
- {
- // Previous math failed to take ampersand into account
- char dest[charsRequired + 1 - 1];
- int charsWritten;
- ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
- &charsWritten, spaceToPlus, normalizeBreaks)
- == URI_ERROR_OUTPUT_TOO_LARGE);
- }
-}
-
-TEST(UriSuite, TestFreeCrashBug20080827) {
- char const * const sourceUri = "abc";
- char const * const baseUri = "http://www.example.org/";
-
- int res;
- UriParserStateA state;
- UriUriA absoluteDest;
- UriUriA relativeSource;
- UriUriA absoluteBase;
-
- state.uri = &relativeSource;
- res = uriParseUriA(&state, sourceUri);
- ASSERT_TRUE(res == URI_SUCCESS);
-
- state.uri = &absoluteBase;
- res = uriParseUriA(&state, baseUri);
- ASSERT_TRUE(res == URI_SUCCESS);
-
- res = uriRemoveBaseUriA(&absoluteDest, &relativeSource, &absoluteBase, URI_FALSE);
- ASSERT_TRUE(res == URI_ERROR_REMOVEBASE_REL_SOURCE);
-
- uriFreeUriMembersA(&relativeSource);
- uriFreeUriMembersA(&absoluteBase);
- uriFreeUriMembersA(&absoluteDest); // Crashed here
-}
-
-TEST(UriSuite, TestInvalidInputBug16) {
- UriParserStateA stateA;
- UriUriA uriA;
- stateA.uri = &uriA;
- const char * const input = "A>B";
-
- const int res = uriParseUriA(&stateA, input);
-
- ASSERT_TRUE(res == URI_ERROR_SYNTAX);
- ASSERT_TRUE(stateA.errorPos == input + 1);
- ASSERT_TRUE(stateA.errorCode == URI_ERROR_SYNTAX); /* failed previously */
-
- uriFreeUriMembersA(&uriA);
-}
-
-namespace {
- void testEqualsHelper(const char * uri_to_test) {
- UriParserStateA state;
- UriUriA uriOne;
- UriUriA uriTwo;
- state.uri = &uriOne;
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
- state.uri = &uriTwo;
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
- ASSERT_TRUE(URI_TRUE == uriEqualsUriA(&uriOne, &uriTwo));
- uriFreeUriMembersA(&uriOne);
- uriFreeUriMembersA(&uriTwo);
- }
-} // namespace
-
-TEST(UriSuite, TestEquals) {
- testEqualsHelper("http://host");
- testEqualsHelper("http://host:123");
- testEqualsHelper("http://foo:bar@host:123");
- testEqualsHelper("http://foo:bar@host:123/");
- testEqualsHelper("http://foo:bar@host:123/path");
- testEqualsHelper("http://foo:bar@host:123/path?query");
- testEqualsHelper("http://foo:bar@host:123/path?query#fragment");
-
- testEqualsHelper("path");
- testEqualsHelper("/path");
- testEqualsHelper("/path/");
- testEqualsHelper("//path/");
- testEqualsHelper("//host");
- testEqualsHelper("//host:123");
-}
-
-TEST(UriSuite, TestHostTextTerminationIssue15) {
- UriParserStateA state;
- UriUriA uri;
- state.uri = &uri;
-
- // Empty host and port
- const char * const emptyHostWithPortUri = "//:123";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, emptyHostWithPortUri));
- ASSERT_TRUE(uri.hostText.first == emptyHostWithPortUri + strlen("//"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
- ASSERT_TRUE(uri.portText.first == emptyHostWithPortUri
- + strlen("//:"));
- ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
- + strlen("123"));
- uriFreeUriMembersA(&uri);
-
- // Non-empty host and port
- const char * const hostWithPortUri = "//h:123";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostWithPortUri));
- ASSERT_TRUE(uri.hostText.first == hostWithPortUri + strlen("//"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
- + strlen("h"));
- ASSERT_TRUE(uri.portText.first == hostWithPortUri + strlen("//h:"));
- ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
- + strlen("123"));
- uriFreeUriMembersA(&uri);
-
- // Empty host, empty user info
- const char * const emptyHostEmptyUserInfoUri = "//@";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
- emptyHostEmptyUserInfoUri));
- ASSERT_TRUE(uri.userInfo.first == emptyHostEmptyUserInfoUri
- + strlen("//"));
- ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
- ASSERT_TRUE(uri.hostText.first == emptyHostEmptyUserInfoUri
- + strlen("//@"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
- uriFreeUriMembersA(&uri);
-
- // Non-empty host, empty user info
- const char * const hostEmptyUserInfoUri = "//@h";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostEmptyUserInfoUri));
- ASSERT_TRUE(uri.userInfo.first == hostEmptyUserInfoUri + strlen("//"));
- ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
- ASSERT_TRUE(uri.hostText.first == hostEmptyUserInfoUri
- + strlen("//@"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
- + strlen("h"));
- uriFreeUriMembersA(&uri);
-
- // Empty host, non-empty user info
- const char * const emptyHostWithUserInfoUri = "//:@";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
- emptyHostWithUserInfoUri));
- ASSERT_TRUE(uri.userInfo.first == emptyHostWithUserInfoUri
- + strlen("//"));
- ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 1);
- ASSERT_TRUE(uri.hostText.first == emptyHostWithUserInfoUri
- + strlen("//:@"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
- uriFreeUriMembersA(&uri);
-
- // Exact case from issue #15
- const char * const issue15Uri = "//:%aa@";
- ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, issue15Uri));
- ASSERT_TRUE(uri.userInfo.first == issue15Uri + strlen("//"));
- ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first
- + strlen(":%aa"));
- ASSERT_TRUE(uri.hostText.first == issue15Uri + strlen("//:%aa@"));
- ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
- uriFreeUriMembersA(&uri);
-}
-
-namespace {
- void testCompareRangeHelper(const char * a, const char * b, int expected, bool avoidNullRange = true) {
- UriTextRangeA ra;
- UriTextRangeA rb;
-
- if (a) {
- ra.first = a;
- ra.afterLast = a + strlen(a);
- } else {
- ra.first = NULL;
- ra.afterLast = NULL;
- }
-
- if (b) {
- rb.first = b;
- rb.afterLast = b + strlen(b);
- } else {
- rb.first = NULL;
- rb.afterLast = NULL;
- }
-
- const int received = uriCompareRangeA(
- ((a == NULL) && avoidNullRange) ? NULL : &ra,
- ((b == NULL) && avoidNullRange) ? NULL : &rb);
- if (received != expected) {
- printf("Comparing <%s> to <%s> yields %d, expected %d.\n",
- a, b, received, expected);
- }
- ASSERT_TRUE(received == expected);
- }
-} // namespace
-
-TEST(UriSuite, TestRangeComparison) {
- testCompareRangeHelper("", "", 0);
- testCompareRangeHelper("a", "", 1);
- testCompareRangeHelper("", "a", -1);
-
- testCompareRangeHelper("a", "a", 0);
- testCompareRangeHelper("a", "b", -1);
- testCompareRangeHelper("b", "a", 1);
-
- testCompareRangeHelper("a", "aa", -1);
- testCompareRangeHelper("aa", "a", 1);
-
- // Fixed with 0.8.1:
- testCompareRangeHelper(NULL, "a", -1);
- testCompareRangeHelper("a", NULL, 1);
- testCompareRangeHelper(NULL, NULL, 0);
-
- // Fixed with 0.8.3
- const bool KEEP_NULL_RANGE = false;
- const bool AVOID_NULL_RANGE = true;
- testCompareRangeHelper(NULL, "", -1, AVOID_NULL_RANGE);
- testCompareRangeHelper(NULL, "", -1, KEEP_NULL_RANGE);
- testCompareRangeHelper("", NULL, 1, AVOID_NULL_RANGE);
- testCompareRangeHelper("", NULL, 1, KEEP_NULL_RANGE);
-}
-
-namespace {
- void testRemoveBaseUriHelper(const char * expected,
- const char * absSourceStr,
- const char * absBaseStr) {
- UriParserStateA state;
- UriUriA absSource;
- UriUriA absBase;
- UriUriA dest;
-
- state.uri = &absSource;
- ASSERT_TRUE(uriParseUriA(&state, absSourceStr) == URI_SUCCESS);
-
- state.uri = &absBase;
- ASSERT_TRUE(uriParseUriA(&state, absBaseStr) == URI_SUCCESS);
-
- ASSERT_TRUE(uriRemoveBaseUriA(&dest, &absSource, &absBase, URI_FALSE)
- == URI_SUCCESS);
-
- int size = 0;
- ASSERT_TRUE(uriToStringCharsRequiredA(&dest, &size) == URI_SUCCESS);
- char * const buffer = (char *)malloc(size + 1);
- ASSERT_TRUE(buffer);
- ASSERT_TRUE(uriToStringA(buffer, &dest, size + 1, &size)
- == URI_SUCCESS);
- if (strcmp(buffer, expected)) {
- printf("Expected \"%s\" but got \"%s\"\n", expected, buffer);
- ASSERT_TRUE(0);
- }
- free(buffer);
-
- uriFreeUriMembersA(&absSource);
- uriFreeUriMembersA(&absBase);
- uriFreeUriMembersA(&dest);
- }
-} // namespace
-
-TEST(UriSuite, TestRangeComparisonRemoveBaseUriIssue19) {
- // scheme
- testRemoveBaseUriHelper("scheme://host/source",
- "scheme://host/source",
- "schemelonger://host/base");
- testRemoveBaseUriHelper("schemelonger://host/source",
- "schemelonger://host/source",
- "scheme://host/base");
-
- // hostText
- testRemoveBaseUriHelper("//host/source",
- "http://host/source",
- "http://hostlonger/base");
- testRemoveBaseUriHelper("//hostlonger/source",
- "http://hostlonger/source",
- "http://host/base");
-
- // hostData.ipFuture
- testRemoveBaseUriHelper("//[v7.host]/source",
- "http://[v7.host]/source",
- "http://[v7.hostlonger]/base");
- testRemoveBaseUriHelper("//[v7.hostlonger]/source",
- "http://[v7.hostlonger]/source",
- "http://host/base");
-
- // path
- testRemoveBaseUriHelper("path1",
- "http://host/path1",
- "http://host/path111");
- testRemoveBaseUriHelper("../path1/path2",
- "http://host/path1/path2",
- "http://host/path111/path222");
- testRemoveBaseUriHelper("path111",
- "http://host/path111",
- "http://host/path1");
- testRemoveBaseUriHelper("../path111/path222",
- "http://host/path111/path222",
- "http://host/path1/path2");
-
- // Exact issue #19
- testRemoveBaseUriHelper("//example/x/abc",
- "http://example/x/abc",
- "http://example2/x/y/z");
-}
-
-TEST(ErrorPosSuite, TestErrorPosIPvFuture) {
- UriUriA uri;
- const char * errorPos;
-
- const char * const uriText = "http://[vA.123456"; // missing "]"
- EXPECT_EQ(uriParseSingleUriA(&uri, uriText, &errorPos),
- URI_ERROR_SYNTAX);
- EXPECT_EQ(errorPos, uriText + strlen(uriText));
-}
-
-TEST(UriParseSingleSuite, Success) {
- UriUriA uri;
-
- EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
- URI_SUCCESS);
-
- uriFreeUriMembersA(&uri);
-}
-
-TEST(UriParseSingleSuite, ErrorSyntaxParseErrorSetsErrorPos) {
- UriUriA uri;
- const char * errorPos;
- const char * const uriString = "abc{}def";
-
- EXPECT_EQ(uriParseSingleUriA(&uri, uriString, &errorPos),
- URI_ERROR_SYNTAX);
- EXPECT_EQ(errorPos, uriString + strlen("abc"));
-
- uriFreeUriMembersA(&uri);
-}
-
-TEST(UriParseSingleSuite, ErrorNullFirstDetected) {
- UriUriA uri;
- const char * errorPos;
-
- EXPECT_EQ(uriParseSingleUriExA(&uri, NULL, "notnull", &errorPos),
- URI_ERROR_NULL);
-}
-
-TEST(UriParseSingleSuite, ErrorNullAfterLastDetected) {
- UriUriA uri;
-
- EXPECT_EQ(uriParseSingleUriExA(&uri, "foo", NULL, NULL), URI_SUCCESS);
-
- uriFreeUriMembersA(&uri);
-}
-
-TEST(UriParseSingleSuite, ErrorNullMemoryManagerDetected) {
- UriUriA uri;
- const char * errorPos;
- const char * const uriString = "somethingwellformed";
-
- EXPECT_EQ(uriParseSingleUriExMmA(&uri,
- uriString,
- uriString + strlen(uriString),
- &errorPos, NULL), URI_SUCCESS);
-
- EXPECT_EQ(uriFreeUriMembersMmA(&uri, NULL), URI_SUCCESS);
-}
-
-TEST(FreeUriMembersSuite, MultiFreeWorksFine) {
- UriUriA uri;
-
- EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
- URI_SUCCESS);
-
- UriUriA uriBackup = uri;
- EXPECT_EQ(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
-
- uriFreeUriMembersA(&uri);
-
- // Did some pointers change (to NULL)?
- EXPECT_NE(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
-
- uriFreeUriMembersA(&uri); // second time
-}
-
+TEST(UriSuite, TestNormalizeCrashBug20080224) {
+ UriParserStateW stateW;
+ int res;
+ UriUriW testUri;
+ stateW.uri = &testUri;
+
+ res = uriParseUriW(&stateW, L"http://example.org/abc//../def");
+ ASSERT_TRUE(res == 0);
+
+ // First call will make us owner of copied memory
+ res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_SCHEME);
+ ASSERT_TRUE(res == 0);
+ res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_HOST);
+ ASSERT_TRUE(res == 0);
+
+ // Frees empty path segment -> crash
+ res = uriNormalizeSyntaxW(&testUri);
+ ASSERT_TRUE(res == 0);
+
+ uriFreeUriMembersW(&testUri);
+}
+
+namespace {
+ void testFilenameUriConversionHelper(const wchar_t * filename,
+ const wchar_t * uriString, bool forUnix,
+ const wchar_t * expectedUriString = NULL) {
+ const int prefixLen = forUnix ? 7 : 8;
+ if (! expectedUriString) {
+ expectedUriString = uriString;
+ }
+
+ // Filename to URI string
+ const size_t uriBufferLen = prefixLen + 3 * wcslen(filename) + 1;
+ wchar_t * uriBuffer = new wchar_t[uriBufferLen];
+ if (forUnix) {
+ uriUnixFilenameToUriStringW(filename, uriBuffer);
+ } else {
+ uriWindowsFilenameToUriStringW(filename, uriBuffer);
+ }
+#ifdef HAVE_WPRINTF
+ // wprintf(L"1 [%s][%s]\n", uriBuffer, expectedUriString);
+#endif
+ ASSERT_TRUE(!wcscmp(uriBuffer, expectedUriString));
+ delete [] uriBuffer;
+
+ // URI string to filename
+ const size_t filenameBufferLen = wcslen(uriString) + 1;
+ wchar_t * filenameBuffer = new wchar_t[filenameBufferLen];
+ if (forUnix) {
+ uriUriStringToUnixFilenameW(uriString, filenameBuffer);
+ } else {
+ uriUriStringToWindowsFilenameW(uriString, filenameBuffer);
+ }
+#ifdef HAVE_WPRINTF
+ // wprintf(L"2 [%s][%s]\n", filenameBuffer, filename);
+#endif
+ ASSERT_TRUE(!wcscmp(filenameBuffer, filename));
+ delete [] filenameBuffer;
+ }
+} // namespace
+
+TEST(UriSuite, TestFilenameUriConversion) {
+ const bool FOR_UNIX = true;
+ const bool FOR_WINDOWS = false;
+ testFilenameUriConversionHelper(L"/bin/bash", L"file:///bin/bash", FOR_UNIX);
+ testFilenameUriConversionHelper(L"/bin/bash", L"file:/bin/bash", FOR_UNIX, L"file:///bin/bash");
+ testFilenameUriConversionHelper(L"./configure", L"./configure", FOR_UNIX);
+
+ testFilenameUriConversionHelper(L"E:\\Documents and Settings", L"file:///E:/Documents%20and%20Settings", FOR_WINDOWS);
+ testFilenameUriConversionHelper(L"c:\\path\\to\\file.txt", L"file:c:/path/to/file.txt", FOR_WINDOWS, L"file:///c:/path/to/file.txt");
+
+ testFilenameUriConversionHelper(L".\\Readme.txt", L"./Readme.txt", FOR_WINDOWS);
+
+ testFilenameUriConversionHelper(L"index.htm", L"index.htm", FOR_WINDOWS);
+ testFilenameUriConversionHelper(L"index.htm", L"index.htm", FOR_UNIX);
+
+ testFilenameUriConversionHelper(L"abc def", L"abc%20def", FOR_WINDOWS);
+ testFilenameUriConversionHelper(L"abc def", L"abc%20def", FOR_UNIX);
+
+ testFilenameUriConversionHelper(L"\\\\Server01\\user\\docs\\Letter.txt", L"file://Server01/user/docs/Letter.txt", FOR_WINDOWS);
+}
+
+TEST(UriSuite, TestCrashFreeUriMembersBug20080116) {
+ // Testcase by Adrian Manrique
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+ uriParseUriA(&state, "http://test/?");
+ uriNormalizeSyntaxA(&uri);
+ uriFreeUriMembersA(&uri);
+
+ ASSERT_TRUE(true);
+}
+
+namespace {
+ void helperTestQueryString(char const * uriString, int pairsExpected);
+}
+
+TEST(UriSuite, TestCrashReport2418192) {
+ // Testcase by Harvey Vrsalovic
+ helperTestQueryString("http://svcs.cnn.com/weather/wrapper.jsp?&csiID=csi1", 1);
+}
+
+TEST(UriSuite, TestPervertedQueryString) {
+ helperTestQueryString("http://example.org/?&&=&&&=&&&&==&===&====", 5);
+}
+
+TEST(UriSuite, TestQueryStringEndingInEqualSignNonBug32) {
+ const char * queryString = "firstname=sdsd&lastname=";
+
+ UriQueryListA * queryList = NULL;
+ int itemCount = 0;
+ const int res = uriDissectQueryMallocA(&queryList, &itemCount,
+ queryString, queryString + strlen(queryString));
+
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(itemCount == 2);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(strcmp(queryList->key, "firstname") == 0);
+ ASSERT_TRUE(strcmp(queryList->value, "sdsd") == 0);
+ ASSERT_TRUE(strcmp(queryList->next->key, "lastname") == 0);
+ ASSERT_TRUE(strcmp(queryList->next->value, "") == 0);
+ ASSERT_TRUE(queryList->next->next == NULL);
+
+ uriFreeQueryListA(queryList);
+}
+
+namespace {
+ void helperTestQueryString(char const * uriString, int pairsExpected) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+ int res = uriParseUriA(&state, uriString);
+ ASSERT_TRUE(res == URI_SUCCESS);
+
+ UriQueryListA * queryList = NULL;
+ int itemCount = 0;
+
+ res = uriDissectQueryMallocA(&queryList, &itemCount,
+ uri.query.first, uri.query.afterLast);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == pairsExpected);
+ uriFreeQueryListA(queryList);
+ uriFreeUriMembersA(&uri);
+ }
+} // namespace
+
+TEST(UriSuite, TestCrashMakeOwnerBug20080207) {
+ // Testcase by Adrian Manrique
+ UriParserStateA state;
+ UriUriA sourceUri;
+ state.uri = &sourceUri;
+ const char * const sourceUriString = "http://user:pass@somehost.com:80/";
+ if (uriParseUriA(&state, sourceUriString) != 0) {
+ ASSERT_TRUE(false);
+ }
+ if (uriNormalizeSyntaxA(&sourceUri) != 0) {
+ ASSERT_TRUE(false);
+ }
+ uriFreeUriMembersA(&sourceUri);
+ ASSERT_TRUE(true);
+}
+
+namespace {
+ void testQueryListHelper(const wchar_t * input, int expectedItemCount) {
+ int res;
+
+ UriBool spacePlusConversion = URI_TRUE;
+ UriBool normalizeBreaks = URI_FALSE;
+ UriBreakConversion breakConversion = URI_BR_DONT_TOUCH;
+
+ int itemCount;
+ UriQueryListW * queryList;
+ res = uriDissectQueryMallocExW(&queryList, &itemCount,
+ input, input + wcslen(input), spacePlusConversion, breakConversion);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(itemCount == expectedItemCount);
+ ASSERT_TRUE((queryList == NULL) == (expectedItemCount == 0));
+
+ if (expectedItemCount != 0) {
+ // First
+ int charsRequired;
+ res = uriComposeQueryCharsRequiredExW(queryList, &charsRequired, spacePlusConversion,
+ normalizeBreaks);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(charsRequired >= (int)wcslen(input));
+
+ wchar_t * recomposed = new wchar_t[charsRequired + 1];
+ int charsWritten;
+ res = uriComposeQueryExW(recomposed, queryList, charsRequired + 1,
+ &charsWritten, spacePlusConversion, normalizeBreaks);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(charsWritten <= charsRequired);
+ ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
+ ASSERT_TRUE(!wcscmp(input, recomposed));
+ delete [] recomposed;
+
+ recomposed = NULL;
+ res = uriComposeQueryMallocW(&recomposed, queryList);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(recomposed != NULL);
+ ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
+ ASSERT_TRUE(!wcscmp(input, recomposed));
+ free(recomposed);
+ }
+
+ uriFreeQueryListW(queryList);
+ }
+} // namespace
+
+TEST(UriSuite, QueryList) {
+ testQueryListHelper(L"one=ONE&two=TWO", 2);
+ testQueryListHelper(L"one=ONE&two=&three=THREE", 3);
+ testQueryListHelper(L"one=ONE&two&three=THREE", 3);
+ testQueryListHelper(L"one=ONE", 1);
+ testQueryListHelper(L"one", 1);
+ testQueryListHelper(L"", 0);
+}
+
+namespace {
+ void testQueryListPairHelper(const char * pair, const char * unescapedKey,
+ const char * unescapedValue, const char * fixed = NULL) {
+ int res;
+ UriQueryListA * queryList;
+ int itemCount;
+
+ res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == 1);
+ ASSERT_TRUE(!strcmp(queryList->key, unescapedKey));
+ ASSERT_TRUE(!strcmp(queryList->value, unescapedValue));
+
+ char * recomposed;
+ res = uriComposeQueryMallocA(&recomposed, queryList);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(recomposed != NULL);
+ ASSERT_TRUE(!strcmp(recomposed, (fixed != NULL) ? fixed : pair));
+ free(recomposed);
+ uriFreeQueryListA(queryList);
+ }
+} // namespace
+
+TEST(UriSuite, TestQueryListPair) {
+ testQueryListPairHelper("one+two+%26+three=%2B", "one two & three", "+");
+ testQueryListPairHelper("one=two=three", "one", "two=three", "one=two%3Dthree");
+ testQueryListPairHelper("one=two=three=four", "one", "two=three=four", "one=two%3Dthree%3Dfour");
+}
+
+TEST(UriSuite, TestQueryDissectionBug3590761) {
+ int res;
+ UriQueryListA * queryList;
+ int itemCount;
+ const char * const pair = "q=hello&x=&y=";
+
+ res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == 3);
+
+ ASSERT_TRUE(!strcmp(queryList->key, "q"));
+ ASSERT_TRUE(!strcmp(queryList->value, "hello"));
+
+ ASSERT_TRUE(!strcmp(queryList->next->key, "x"));
+ ASSERT_TRUE(!strcmp(queryList->next->value, ""));
+
+ ASSERT_TRUE(!strcmp(queryList->next->next->key, "y"));
+ ASSERT_TRUE(!strcmp(queryList->next->next->value, ""));
+
+ ASSERT_TRUE(! queryList->next->next->next);
+
+ uriFreeQueryListA(queryList);
+}
+
+TEST(UriSuite, TestQueryCompositionMathCalc) {
+ UriQueryListA second = { /*.key =*/ "k2", /*.value =*/ "v2", /*.next =*/ NULL };
+ UriQueryListA first = { /*.key =*/ "k1", /*.value =*/ "v1", /*.next =*/ &second };
+
+ int charsRequired;
+ ASSERT_TRUE(uriComposeQueryCharsRequiredA(&first, &charsRequired)
+ == URI_SUCCESS);
+
+ const int FACTOR = 6; /* due to escaping with normalizeBreaks */
+ ASSERT_TRUE((unsigned)charsRequired ==
+ FACTOR * strlen(first.key) + 1 + FACTOR * strlen(first.value)
+ + 1
+ + FACTOR * strlen(second.key) + 1 + FACTOR * strlen(second.value)
+ );
+}
+
+TEST(UriSuite, TestQueryCompositionMathWriteGoogleAutofuzz113244572) {
+ UriQueryListA second = { /*.key =*/ "\x11", /*.value =*/ NULL, /*.next =*/ NULL };
+ UriQueryListA first = { /*.key =*/ "\x01", /*.value =*/ "\x02", /*.next =*/ &second };
+
+ const UriBool spaceToPlus = URI_TRUE;
+ const UriBool normalizeBreaks = URI_FALSE; /* for factor 3 but 6 */
+
+ const int charsRequired = (3 + 1 + 3) + 1 + (3);
+
+ {
+ // Minimum space to hold everything fine
+ const char * const expected = "%01=%02" "&" "%11";
+ char dest[charsRequired + 1];
+ int charsWritten;
+ ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
+ &charsWritten, spaceToPlus, normalizeBreaks)
+ == URI_SUCCESS);
+ ASSERT_TRUE(! strcmp(dest, expected));
+ ASSERT_TRUE(charsWritten == strlen(expected) + 1);
+ }
+
+ {
+ // Previous math failed to take ampersand into account
+ char dest[charsRequired + 1 - 1];
+ int charsWritten;
+ ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
+ &charsWritten, spaceToPlus, normalizeBreaks)
+ == URI_ERROR_OUTPUT_TOO_LARGE);
+ }
+}
+
+TEST(UriSuite, TestFreeCrashBug20080827) {
+ char const * const sourceUri = "abc";
+ char const * const baseUri = "http://www.example.org/";
+
+ int res;
+ UriParserStateA state;
+ UriUriA absoluteDest;
+ UriUriA relativeSource;
+ UriUriA absoluteBase;
+
+ state.uri = &relativeSource;
+ res = uriParseUriA(&state, sourceUri);
+ ASSERT_TRUE(res == URI_SUCCESS);
+
+ state.uri = &absoluteBase;
+ res = uriParseUriA(&state, baseUri);
+ ASSERT_TRUE(res == URI_SUCCESS);
+
+ res = uriRemoveBaseUriA(&absoluteDest, &relativeSource, &absoluteBase, URI_FALSE);
+ ASSERT_TRUE(res == URI_ERROR_REMOVEBASE_REL_SOURCE);
+
+ uriFreeUriMembersA(&relativeSource);
+ uriFreeUriMembersA(&absoluteBase);
+ uriFreeUriMembersA(&absoluteDest); // Crashed here
+}
+
+TEST(UriSuite, TestInvalidInputBug16) {
+ UriParserStateA stateA;
+ UriUriA uriA;
+ stateA.uri = &uriA;
+ const char * const input = "A>B";
+
+ const int res = uriParseUriA(&stateA, input);
+
+ ASSERT_TRUE(res == URI_ERROR_SYNTAX);
+ ASSERT_TRUE(stateA.errorPos == input + 1);
+ ASSERT_TRUE(stateA.errorCode == URI_ERROR_SYNTAX); /* failed previously */
+
+ uriFreeUriMembersA(&uriA);
+}
+
+namespace {
+ void testEqualsHelper(const char * uri_to_test) {
+ UriParserStateA state;
+ UriUriA uriOne;
+ UriUriA uriTwo;
+ state.uri = &uriOne;
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
+ state.uri = &uriTwo;
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
+ ASSERT_TRUE(URI_TRUE == uriEqualsUriA(&uriOne, &uriTwo));
+ uriFreeUriMembersA(&uriOne);
+ uriFreeUriMembersA(&uriTwo);
+ }
+} // namespace
+
+TEST(UriSuite, TestEquals) {
+ testEqualsHelper("http://host");
+ testEqualsHelper("http://host:123");
+ testEqualsHelper("http://foo:bar@host:123");
+ testEqualsHelper("http://foo:bar@host:123/");
+ testEqualsHelper("http://foo:bar@host:123/path");
+ testEqualsHelper("http://foo:bar@host:123/path?query");
+ testEqualsHelper("http://foo:bar@host:123/path?query#fragment");
+
+ testEqualsHelper("path");
+ testEqualsHelper("/path");
+ testEqualsHelper("/path/");
+ testEqualsHelper("//path/");
+ testEqualsHelper("//host");
+ testEqualsHelper("//host:123");
+}
+
+TEST(UriSuite, TestHostTextTerminationIssue15) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+
+ // Empty host and port
+ const char * const emptyHostWithPortUri = "//:123";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, emptyHostWithPortUri));
+ ASSERT_TRUE(uri.hostText.first == emptyHostWithPortUri + strlen("//"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
+ ASSERT_TRUE(uri.portText.first == emptyHostWithPortUri
+ + strlen("//:"));
+ ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
+ + strlen("123"));
+ uriFreeUriMembersA(&uri);
+
+ // Non-empty host and port
+ const char * const hostWithPortUri = "//h:123";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostWithPortUri));
+ ASSERT_TRUE(uri.hostText.first == hostWithPortUri + strlen("//"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
+ + strlen("h"));
+ ASSERT_TRUE(uri.portText.first == hostWithPortUri + strlen("//h:"));
+ ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
+ + strlen("123"));
+ uriFreeUriMembersA(&uri);
+
+ // Empty host, empty user info
+ const char * const emptyHostEmptyUserInfoUri = "//@";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
+ emptyHostEmptyUserInfoUri));
+ ASSERT_TRUE(uri.userInfo.first == emptyHostEmptyUserInfoUri
+ + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ ASSERT_TRUE(uri.hostText.first == emptyHostEmptyUserInfoUri
+ + strlen("//@"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+
+ // Non-empty host, empty user info
+ const char * const hostEmptyUserInfoUri = "//@h";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostEmptyUserInfoUri));
+ ASSERT_TRUE(uri.userInfo.first == hostEmptyUserInfoUri + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ ASSERT_TRUE(uri.hostText.first == hostEmptyUserInfoUri
+ + strlen("//@"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
+ + strlen("h"));
+ uriFreeUriMembersA(&uri);
+
+ // Empty host, non-empty user info
+ const char * const emptyHostWithUserInfoUri = "//:@";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
+ emptyHostWithUserInfoUri));
+ ASSERT_TRUE(uri.userInfo.first == emptyHostWithUserInfoUri
+ + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 1);
+ ASSERT_TRUE(uri.hostText.first == emptyHostWithUserInfoUri
+ + strlen("//:@"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+
+ // Exact case from issue #15
+ const char * const issue15Uri = "//:%aa@";
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, issue15Uri));
+ ASSERT_TRUE(uri.userInfo.first == issue15Uri + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first
+ + strlen(":%aa"));
+ ASSERT_TRUE(uri.hostText.first == issue15Uri + strlen("//:%aa@"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+}
+
+namespace {
+ void testCompareRangeHelper(const char * a, const char * b, int expected, bool avoidNullRange = true) {
+ UriTextRangeA ra;
+ UriTextRangeA rb;
+
+ if (a) {
+ ra.first = a;
+ ra.afterLast = a + strlen(a);
+ } else {
+ ra.first = NULL;
+ ra.afterLast = NULL;
+ }
+
+ if (b) {
+ rb.first = b;
+ rb.afterLast = b + strlen(b);
+ } else {
+ rb.first = NULL;
+ rb.afterLast = NULL;
+ }
+
+ const int received = uriCompareRangeA(
+ ((a == NULL) && avoidNullRange) ? NULL : &ra,
+ ((b == NULL) && avoidNullRange) ? NULL : &rb);
+ if (received != expected) {
+ printf("Comparing <%s> to <%s> yields %d, expected %d.\n",
+ a, b, received, expected);
+ }
+ ASSERT_TRUE(received == expected);
+ }
+} // namespace
+
+TEST(UriSuite, TestRangeComparison) {
+ testCompareRangeHelper("", "", 0);
+ testCompareRangeHelper("a", "", 1);
+ testCompareRangeHelper("", "a", -1);
+
+ testCompareRangeHelper("a", "a", 0);
+ testCompareRangeHelper("a", "b", -1);
+ testCompareRangeHelper("b", "a", 1);
+
+ testCompareRangeHelper("a", "aa", -1);
+ testCompareRangeHelper("aa", "a", 1);
+
+ // Fixed with 0.8.1:
+ testCompareRangeHelper(NULL, "a", -1);
+ testCompareRangeHelper("a", NULL, 1);
+ testCompareRangeHelper(NULL, NULL, 0);
+
+ // Fixed with 0.8.3
+ const bool KEEP_NULL_RANGE = false;
+ const bool AVOID_NULL_RANGE = true;
+ testCompareRangeHelper(NULL, "", -1, AVOID_NULL_RANGE);
+ testCompareRangeHelper(NULL, "", -1, KEEP_NULL_RANGE);
+ testCompareRangeHelper("", NULL, 1, AVOID_NULL_RANGE);
+ testCompareRangeHelper("", NULL, 1, KEEP_NULL_RANGE);
+}
+
+namespace {
+ void testRemoveBaseUriHelper(const char * expected,
+ const char * absSourceStr,
+ const char * absBaseStr) {
+ UriParserStateA state;
+ UriUriA absSource;
+ UriUriA absBase;
+ UriUriA dest;
+
+ state.uri = &absSource;
+ ASSERT_TRUE(uriParseUriA(&state, absSourceStr) == URI_SUCCESS);
+
+ state.uri = &absBase;
+ ASSERT_TRUE(uriParseUriA(&state, absBaseStr) == URI_SUCCESS);
+
+ ASSERT_TRUE(uriRemoveBaseUriA(&dest, &absSource, &absBase, URI_FALSE)
+ == URI_SUCCESS);
+
+ int size = 0;
+ ASSERT_TRUE(uriToStringCharsRequiredA(&dest, &size) == URI_SUCCESS);
+ char * const buffer = (char *)malloc(size + 1);
+ ASSERT_TRUE(buffer);
+ ASSERT_TRUE(uriToStringA(buffer, &dest, size + 1, &size)
+ == URI_SUCCESS);
+ if (strcmp(buffer, expected)) {
+ printf("Expected \"%s\" but got \"%s\"\n", expected, buffer);
+ ASSERT_TRUE(0);
+ }
+ free(buffer);
+
+ uriFreeUriMembersA(&absSource);
+ uriFreeUriMembersA(&absBase);
+ uriFreeUriMembersA(&dest);
+ }
+} // namespace
+
+TEST(UriSuite, TestRangeComparisonRemoveBaseUriIssue19) {
+ // scheme
+ testRemoveBaseUriHelper("scheme://host/source",
+ "scheme://host/source",
+ "schemelonger://host/base");
+ testRemoveBaseUriHelper("schemelonger://host/source",
+ "schemelonger://host/source",
+ "scheme://host/base");
+
+ // hostText
+ testRemoveBaseUriHelper("//host/source",
+ "http://host/source",
+ "http://hostlonger/base");
+ testRemoveBaseUriHelper("//hostlonger/source",
+ "http://hostlonger/source",
+ "http://host/base");
+
+ // hostData.ipFuture
+ testRemoveBaseUriHelper("//[v7.host]/source",
+ "http://[v7.host]/source",
+ "http://[v7.hostlonger]/base");
+ testRemoveBaseUriHelper("//[v7.hostlonger]/source",
+ "http://[v7.hostlonger]/source",
+ "http://host/base");
+
+ // path
+ testRemoveBaseUriHelper("path1",
+ "http://host/path1",
+ "http://host/path111");
+ testRemoveBaseUriHelper("../path1/path2",
+ "http://host/path1/path2",
+ "http://host/path111/path222");
+ testRemoveBaseUriHelper("path111",
+ "http://host/path111",
+ "http://host/path1");
+ testRemoveBaseUriHelper("../path111/path222",
+ "http://host/path111/path222",
+ "http://host/path1/path2");
+
+ // Exact issue #19
+ testRemoveBaseUriHelper("//example/x/abc",
+ "http://example/x/abc",
+ "http://example2/x/y/z");
+}
+
+TEST(ErrorPosSuite, TestErrorPosIPvFuture) {
+ UriUriA uri;
+ const char * errorPos;
+
+ const char * const uriText = "http://[vA.123456"; // missing "]"
+ EXPECT_EQ(uriParseSingleUriA(&uri, uriText, &errorPos),
+ URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriText + strlen(uriText));
+}
+
+TEST(UriParseSingleSuite, Success) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
+ URI_SUCCESS);
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorSyntaxParseErrorSetsErrorPos) {
+ UriUriA uri;
+ const char * errorPos;
+ const char * const uriString = "abc{}def";
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, uriString, &errorPos),
+ URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriString + strlen("abc"));
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorNullFirstDetected) {
+ UriUriA uri;
+ const char * errorPos;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, NULL, "notnull", &errorPos),
+ URI_ERROR_NULL);
+}
+
+TEST(UriParseSingleSuite, ErrorNullAfterLastDetected) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, "foo", NULL, NULL), URI_SUCCESS);
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorNullMemoryManagerDetected) {
+ UriUriA uri;
+ const char * errorPos;
+ const char * const uriString = "somethingwellformed";
+
+ EXPECT_EQ(uriParseSingleUriExMmA(&uri,
+ uriString,
+ uriString + strlen(uriString),
+ &errorPos, NULL), URI_SUCCESS);
+
+ EXPECT_EQ(uriFreeUriMembersMmA(&uri, NULL), URI_SUCCESS);
+}
+
+TEST(FreeUriMembersSuite, MultiFreeWorksFine) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
+ URI_SUCCESS);
+
+ UriUriA uriBackup = uri;
+ EXPECT_EQ(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
+
+ uriFreeUriMembersA(&uri);
+
+ // Did some pointers change (to NULL)?
+ EXPECT_NE(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
+
+ uriFreeUriMembersA(&uri); // second time
+}
+
namespace {
void testFreeUriMembersFreesHostText(const char *const uriFirst) { // issue #121
const char *const uriAfterLast = uriFirst + strlen(uriFirst);
@@ -2255,65 +2255,65 @@ TEST(FreeUriMembersSuite, FreeUriMembersFreesHostTextFuture) { // issue #121
testFreeUriMembersFreesHostText("//[v7.X]"); // arbitrary IPvFuture
}
-TEST(MakeOwnerSuite, MakeOwner) {
- const char * const uriString = "scheme://user:pass@[v7.X]:55555/path/../path/?query#fragment";
- UriUriA uri;
- char * uriFirst = strdup(uriString);
- const size_t uriLen = strlen(uriFirst);
- char * uriAfterLast = uriFirst + uriLen;
-
- EXPECT_EQ(uriParseSingleUriExA(&uri, uriFirst, uriAfterLast, NULL), URI_SUCCESS);
-
- // After plain parse, all strings should point inside the original URI string
- EXPECT_EQ(uri.owner, URI_FALSE);
- URI_EXPECT_RANGE_BETWEEN(uri.scheme, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.userInfo, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.hostText, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.hostData.ipFuture, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.portText, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.pathHead->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
- EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
- URI_EXPECT_RANGE_BETWEEN(uri.query, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_BETWEEN(uri.fragment, uriFirst, uriAfterLast);
-
- EXPECT_EQ(uriMakeOwnerA(&uri), URI_SUCCESS);
-
- // After making owner, *none* of the strings should point inside the original URI string
- EXPECT_EQ(uri.owner, URI_TRUE);
- URI_EXPECT_RANGE_OUTSIDE(uri.scheme, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.userInfo, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.hostText, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.hostData.ipFuture, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.portText, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
- EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
- URI_EXPECT_RANGE_OUTSIDE(uri.query, uriFirst, uriAfterLast);
- URI_EXPECT_RANGE_OUTSIDE(uri.fragment, uriFirst, uriAfterLast);
-
- // Free originally used memory so we'd get violations on access with ASan
- uriAfterLast = NULL;
- free(uriFirst);
- uriFirst = NULL;
-
- // Can we recompose the URI without accessing any old freed memory?
- int charsRequired;
- EXPECT_EQ(uriToStringCharsRequiredA(&uri, &charsRequired), URI_SUCCESS);
- EXPECT_TRUE((charsRequired >= 0) && (charsRequired >= static_cast<int>(uriLen)));
- char * const uriRemake = new char[charsRequired + 1];
- EXPECT_TRUE(uriRemake != NULL);
- EXPECT_EQ(uriToStringA(uriRemake, &uri, charsRequired + 1, NULL), URI_SUCCESS);
- EXPECT_TRUE(! strcmp(uriString, uriRemake));
- delete [] uriRemake;
-
- uriFreeUriMembersA(&uri);
-}
-
+TEST(MakeOwnerSuite, MakeOwner) {
+ const char * const uriString = "scheme://user:pass@[v7.X]:55555/path/../path/?query#fragment";
+ UriUriA uri;
+ char * uriFirst = strdup(uriString);
+ const size_t uriLen = strlen(uriFirst);
+ char * uriAfterLast = uriFirst + uriLen;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, uriFirst, uriAfterLast, NULL), URI_SUCCESS);
+
+ // After plain parse, all strings should point inside the original URI string
+ EXPECT_EQ(uri.owner, URI_FALSE);
+ URI_EXPECT_RANGE_BETWEEN(uri.scheme, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.userInfo, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.hostText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.hostData.ipFuture, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.portText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
+ EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
+ URI_EXPECT_RANGE_BETWEEN(uri.query, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.fragment, uriFirst, uriAfterLast);
+
+ EXPECT_EQ(uriMakeOwnerA(&uri), URI_SUCCESS);
+
+ // After making owner, *none* of the strings should point inside the original URI string
+ EXPECT_EQ(uri.owner, URI_TRUE);
+ URI_EXPECT_RANGE_OUTSIDE(uri.scheme, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.userInfo, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.hostText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.hostData.ipFuture, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.portText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
+ EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
+ URI_EXPECT_RANGE_OUTSIDE(uri.query, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.fragment, uriFirst, uriAfterLast);
+
+ // Free originally used memory so we'd get violations on access with ASan
+ uriAfterLast = NULL;
+ free(uriFirst);
+ uriFirst = NULL;
+
+ // Can we recompose the URI without accessing any old freed memory?
+ int charsRequired;
+ EXPECT_EQ(uriToStringCharsRequiredA(&uri, &charsRequired), URI_SUCCESS);
+ EXPECT_TRUE((charsRequired >= 0) && (charsRequired >= static_cast<int>(uriLen)));
+ char * const uriRemake = new char[charsRequired + 1];
+ EXPECT_TRUE(uriRemake != NULL);
+ EXPECT_EQ(uriToStringA(uriRemake, &uri, charsRequired + 1, NULL), URI_SUCCESS);
+ EXPECT_TRUE(! strcmp(uriString, uriRemake));
+ delete [] uriRemake;
+
+ uriFreeUriMembersA(&uri);
+}
+
namespace {
void testMakeOwnerCopiesHostText(const char *const uriFirst) { // issue #121
const char *const uriAfterLast = uriFirst + strlen(uriFirst);
@@ -2349,14 +2349,14 @@ TEST(MakeOwnerSuite, MakeOwnerCopiesHostTextFuture) { // issue #121
testMakeOwnerCopiesHostText("//[v7.X]"); // arbitrary IPvFuture
}
-TEST(ParseIpFourAddressSuite, FourSaneOctets) {
- unsigned char octetOutput[4];
- const char * const ipAddressText = "111.22.3.40";
- const int res = uriParseIpFourAddressA(octetOutput, ipAddressText,
- ipAddressText + strlen(ipAddressText));
- EXPECT_EQ(res, URI_SUCCESS);
- EXPECT_EQ(octetOutput[0], 111);
- EXPECT_EQ(octetOutput[1], 22);
- EXPECT_EQ(octetOutput[2], 3);
- EXPECT_EQ(octetOutput[3], 40);
-}
+TEST(ParseIpFourAddressSuite, FourSaneOctets) {
+ unsigned char octetOutput[4];
+ const char * const ipAddressText = "111.22.3.40";
+ const int res = uriParseIpFourAddressA(octetOutput, ipAddressText,
+ ipAddressText + strlen(ipAddressText));
+ EXPECT_EQ(res, URI_SUCCESS);
+ EXPECT_EQ(octetOutput[0], 111);
+ EXPECT_EQ(octetOutput[1], 22);
+ EXPECT_EQ(octetOutput[2], 3);
+ EXPECT_EQ(octetOutput[3], 40);
+}
diff --git a/contrib/restricted/uriparser/test/ya.make b/contrib/restricted/uriparser/test/ya.make
index d7ec8635a4..ae8a32a932 100644
--- a/contrib/restricted/uriparser/test/ya.make
+++ b/contrib/restricted/uriparser/test/ya.make
@@ -1,38 +1,38 @@
-# Generated by devtools/yamaker.
-
-GTEST(testrunner)
-
+# Generated by devtools/yamaker.
+
+GTEST(testrunner)
+
OWNER(
kikht
shindo
g:cpp-contrib
g:mds
)
-
+
LICENSE(
LGPL-2.1-only AND
LGPL-2.1-or-later
)
-
+
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-PEERDIR(
+PEERDIR(
contrib/restricted/uriparser
-)
-
+)
+
ADDINCL(
contrib/restricted/uriparser
)
-
-NO_COMPILER_WARNINGS()
-
-NO_UTIL()
-
-SRCS(
+
+NO_COMPILER_WARNINGS()
+
+NO_UTIL()
+
+SRCS(
FourSuite.cpp
MemoryManagerSuite.cpp
VersionSuite.cpp
test.cpp
-)
-
-END()
+)
+
+END()