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.
This commit is contained in:
Ryan Norton 2019-02-23 14:36:36 +01:00 committed by Vadim Zeitlin
parent 466a2d000f
commit b7f3a2b30f
2 changed files with 22 additions and 0 deletions

View File

@ -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++;

View File

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