summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2018-09-08 10:26:34 +0200
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2018-09-08 10:26:34 +0200
commit04233c1001f3040c0c7811db5178974538ee3680 (patch)
tree6501c4625396503fa7a2df84540b23a93739c441 /test
parente94f3be22cd927eb2b5d9554eae2032a971c7e7e (diff)
parentd7dff546ec47157ba13806d91ff7e6e4836acaf6 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'test')
-rw-r--r--test/test.cpp166
1 files changed, 162 insertions, 4 deletions
diff --git a/test/test.cpp b/test/test.cpp
index 0b1290c..41e3912 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -23,6 +23,7 @@
#include <cpptest.h>
#include <memory>
#include <stdio.h>
+#include <stdlib.h>
#include <wchar.h>
#include "FourSuite.h"
@@ -106,7 +107,9 @@ public:
TEST_ADD(UriSuite::testFreeCrash_Bug20080827)
TEST_ADD(UriSuite::testParseInvalid_Bug16)
TEST_ADD(UriSuite::testRangeComparison)
+ TEST_ADD(UriSuite::testRangeComparison_RemoveBaseUri_Issue19)
TEST_ADD(UriSuite::testEquals)
+ TEST_ADD(UriSuite::testHostTextTermination_Issue15)
}
private:
@@ -150,7 +153,7 @@ 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 | false
| "s://a/"| true | false | true
2) path-absolute | "s:/" | false | true | false
3) path-rootless | "s:a" | false | false | false
@@ -1506,8 +1509,12 @@ Rule | Example | hostSet | absPath | emptySeg
}
void testFilenameUriConversionHelper(const wchar_t * filename,
- const wchar_t * uriString, bool forUnix) {
+ 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;
@@ -1518,9 +1525,9 @@ Rule | Example | hostSet | absPath | emptySeg
uriWindowsFilenameToUriStringW(filename, uriBuffer);
}
#ifdef HAVE_WPRINTF
- // wprintf(L"1 [%s][%s]\n", uriBuffer, uriString);
+ // wprintf(L"1 [%s][%s]\n", uriBuffer, expectedUriString);
#endif
- TEST_ASSERT(!wcscmp(uriBuffer, uriString));
+ TEST_ASSERT(!wcscmp(uriBuffer, expectedUriString));
delete [] uriBuffer;
// URI string to filename
@@ -1542,9 +1549,12 @@ Rule | Example | hostSet | absPath | emptySeg
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);
@@ -1810,6 +1820,79 @@ Rule | Example | hostSet | absPath | emptySeg
testEqualsHelper("//host:123");
}
+ void testHostTextTermination_Issue15() {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+
+ // Empty host and port
+ const char * const emptyHostWithPortUri = "//:123";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, emptyHostWithPortUri));
+ TEST_ASSERT(uri.hostText.first == emptyHostWithPortUri + strlen("//"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ TEST_ASSERT(uri.portText.first == emptyHostWithPortUri
+ + strlen("//:"));
+ TEST_ASSERT(uri.portText.afterLast == uri.portText.first
+ + strlen("123"));
+ uriFreeUriMembersA(&uri);
+
+ // Non-empty host and port
+ const char * const hostWithPortUri = "//h:123";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, hostWithPortUri));
+ TEST_ASSERT(uri.hostText.first == hostWithPortUri + strlen("//"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first
+ + strlen("h"));
+ TEST_ASSERT(uri.portText.first == hostWithPortUri + strlen("//h:"));
+ TEST_ASSERT(uri.portText.afterLast == uri.portText.first
+ + strlen("123"));
+ uriFreeUriMembersA(&uri);
+
+ // Empty host, empty user info
+ const char * const emptyHostEmptyUserInfoUri = "//@";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state,
+ emptyHostEmptyUserInfoUri));
+ TEST_ASSERT(uri.userInfo.first == emptyHostEmptyUserInfoUri
+ + strlen("//"));
+ TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ TEST_ASSERT(uri.hostText.first == emptyHostEmptyUserInfoUri
+ + strlen("//@"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+
+ // Non-empty host, empty user info
+ const char * const hostEmptyUserInfoUri = "//@h";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, hostEmptyUserInfoUri));
+ TEST_ASSERT(uri.userInfo.first == hostEmptyUserInfoUri + strlen("//"));
+ TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ TEST_ASSERT(uri.hostText.first == hostEmptyUserInfoUri
+ + strlen("//@"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first
+ + strlen("h"));
+ uriFreeUriMembersA(&uri);
+
+ // Empty host, non-empty user info
+ const char * const emptyHostWithUserInfoUri = "//:@";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state,
+ emptyHostWithUserInfoUri));
+ TEST_ASSERT(uri.userInfo.first == emptyHostWithUserInfoUri
+ + strlen("//"));
+ TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 1);
+ TEST_ASSERT(uri.hostText.first == emptyHostWithUserInfoUri
+ + strlen("//:@"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+
+ // Exact case from issue #15
+ const char * const issue15Uri = "//:%aa@";
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, issue15Uri));
+ TEST_ASSERT(uri.userInfo.first == issue15Uri + strlen("//"));
+ TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first
+ + strlen(":%aa"));
+ TEST_ASSERT(uri.hostText.first == issue15Uri + strlen("//:%aa@"));
+ TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ uriFreeUriMembersA(&uri);
+ }
+
void testCompareRangeHelper(const char * a, const char * b, int expected, bool avoidNullRange = true) {
UriTextRangeA ra;
UriTextRangeA rb;
@@ -1865,6 +1948,81 @@ Rule | Example | hostSet | absPath | emptySeg
testCompareRangeHelper("", NULL, 1, AVOID_NULL_RANGE);
testCompareRangeHelper("", NULL, 1, KEEP_NULL_RANGE);
}
+
+ void testRemoveBaseUriHelper(const char * expected,
+ const char * absSourceStr,
+ const char * absBaseStr) {
+ UriParserStateA state;
+ UriUriA absSource;
+ UriUriA absBase;
+ UriUriA dest;
+
+ state.uri = &absSource;
+ TEST_ASSERT(uriParseUriA(&state, absSourceStr) == URI_SUCCESS);
+
+ state.uri = &absBase;
+ TEST_ASSERT(uriParseUriA(&state, absBaseStr) == URI_SUCCESS);
+
+ TEST_ASSERT(uriRemoveBaseUriA(&dest, &absSource, &absBase, URI_FALSE)
+ == URI_SUCCESS);
+
+ int size = 0;
+ TEST_ASSERT(uriToStringCharsRequiredA(&dest, &size) == URI_SUCCESS);
+ char * const buffer = (char *)malloc(size + 1);
+ TEST_ASSERT(buffer);
+ TEST_ASSERT(uriToStringA(buffer, &dest, size + 1, &size)
+ == URI_SUCCESS);
+ if (strcmp(buffer, expected)) {
+ printf("Expected \"%s\" but got \"%s\"\n", expected, buffer);
+ TEST_ASSERT(0);
+ }
+ free(buffer);
+ }
+
+ void testRangeComparison_RemoveBaseUri_Issue19() {
+ // 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");
+ }
};