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()