From 466a2d000ff93d5ae826031c17ff4df03cfb35a8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 23 Feb 2019 14:11:58 +0100 Subject: [PATCH 1/2] Use CHECK() in wxURI unit test case This allows the subsequent tests to still run even if one of the tests fails, which is more useful in this test than CPPUNIT_ASSERT_EQUAL(), which maps to REQUIRE() and so stops the test execution as soon as any check fails, because the tests are independent. --- tests/uris/uris.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/uris/uris.cpp b/tests/uris/uris.cpp index 7b88306b58..7ad7189198 100644 --- a/tests/uris/uris.cpp +++ b/tests/uris/uris.cpp @@ -96,7 +96,7 @@ URITestCase::URITestCase() // apply the given accessor to the URI, check that the result is as expected #define URI_ASSERT_PART_EQUAL(uri, expected, accessor) \ - CPPUNIT_ASSERT_EQUAL(expected, wxURI(uri).accessor) + CHECK(wxURI(uri).accessor == expected) #define URI_ASSERT_HOSTTYPE_EQUAL(uri, expected) \ URI_ASSERT_PART_EQUAL((uri), (expected), GetHostType()) From b7f3a2b30f06ea1123a9c0faa4852e8b813cfe3e Mon Sep 17 00:00:00 2001 From: Ryan Norton Date: Sat, 23 Feb 2019 14:36:36 +0100 Subject: [PATCH 2/2] Make parsing wxURI paths more conforming to RFC 3986 Don't recognize the "path" following the port number without a slash as a path, this is invalid according to the RFC. Also require two leading slashes for URIs without the authority part. --- src/common/uri.cpp | 15 +++++++++++++++ tests/uris/uris.cpp | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/common/uri.cpp b/src/common/uri.cpp index e46b0e13d4..4dba8acff7 100644 --- a/src/common/uri.cpp +++ b/src/common/uri.cpp @@ -532,6 +532,21 @@ const char* wxURI::ParsePath(const char* uri) return uri; const bool isAbs = *uri == '/'; + + // From RFC 3986: when authority is present, the path must either be empty + // or begin with a slash ("/") character. When authority is not present, + // the path cannot begin with two slashes. + if ( m_userinfo.empty() && m_server.empty() && m_port.empty() ) + { + if ( isAbs && uri[1] == '/' ) + return uri; + } + else + { + if ( !isAbs ) + return uri; + } + if ( isAbs ) m_path += *uri++; diff --git a/tests/uris/uris.cpp b/tests/uris/uris.cpp index 7ad7189198..42cbf3fd13 100644 --- a/tests/uris/uris.cpp +++ b/tests/uris/uris.cpp @@ -189,6 +189,13 @@ void URITestCase::Paths() URI_ASSERT_PART_EQUAL("path/john/../../../joe", "../joe", BuildURI()); + + // According to RFC 3986, when the authority is present, the path must + // begin with a slash (or be empty) and when there is no authority, the + // path cannot begin with two slashes, so check for this. + URI_ASSERT_PATH_EQUAL("http://good.com:8042BADPATH", ""); + URI_ASSERT_PATH_EQUAL("http://good.com:8042/GOODPATH", "/GOODPATH"); + URI_ASSERT_PATH_EQUAL("//BADPATH", ""); } void URITestCase::UserAndPass()