mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-07 05:58:43 +01:00
trunk/branch integration: bugfix
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// URI.cpp
|
// URI.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/src/URI.cpp#15 $
|
// $Id: //poco/1.4/Foundation/src/URI.cpp#4 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: URI
|
// Package: URI
|
||||||
@@ -226,12 +226,16 @@ std::string URI::toString() const
|
|||||||
if (!_path.empty())
|
if (!_path.empty())
|
||||||
{
|
{
|
||||||
if (!auth.empty() && _path[0] != '/')
|
if (!auth.empty() && _path[0] != '/')
|
||||||
uri += '/';
|
uri += '/';
|
||||||
encode(_path, RESERVED_PATH, uri);
|
encode(_path, RESERVED_PATH, uri);
|
||||||
}
|
}
|
||||||
}
|
else if (!_query.empty() || !_fragment.empty())
|
||||||
if (!_query.empty())
|
{
|
||||||
{
|
uri += '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!_query.empty())
|
||||||
|
{
|
||||||
uri += '?';
|
uri += '?';
|
||||||
uri.append(_query);
|
uri.append(_query);
|
||||||
}
|
}
|
||||||
@@ -286,13 +290,19 @@ std::string URI::getAuthority() const
|
|||||||
std::string auth;
|
std::string auth;
|
||||||
if (!_userInfo.empty())
|
if (!_userInfo.empty())
|
||||||
{
|
{
|
||||||
auth.append(_userInfo);
|
auth.append(_userInfo);
|
||||||
auth += '@';
|
auth += '@';
|
||||||
}
|
}
|
||||||
auth.append(_host);
|
if (_host.find(':') != std::string::npos)
|
||||||
if (_port && !isWellKnownPort())
|
{
|
||||||
{
|
auth += '[';
|
||||||
auth += ':';
|
auth += _host;
|
||||||
|
auth += ']';
|
||||||
|
}
|
||||||
|
else auth.append(_host);
|
||||||
|
if (_port && !isWellKnownPort())
|
||||||
|
{
|
||||||
|
auth += ':';
|
||||||
NumberFormatter::append(auth, _port);
|
NumberFormatter::append(auth, _port);
|
||||||
}
|
}
|
||||||
return auth;
|
return auth;
|
||||||
@@ -360,13 +370,13 @@ std::string URI::getPathEtc() const
|
|||||||
{
|
{
|
||||||
std::string pathEtc;
|
std::string pathEtc;
|
||||||
encode(_path, RESERVED_PATH, pathEtc);
|
encode(_path, RESERVED_PATH, pathEtc);
|
||||||
if (!_query.empty())
|
if (!_query.empty())
|
||||||
{
|
{
|
||||||
pathEtc += '?';
|
pathEtc += '?';
|
||||||
pathEtc.append(_query);
|
pathEtc += _query;
|
||||||
}
|
}
|
||||||
if (!_fragment.empty())
|
if (!_fragment.empty())
|
||||||
{
|
{
|
||||||
pathEtc += '#';
|
pathEtc += '#';
|
||||||
encode(_fragment, RESERVED_FRAGMENT, pathEtc);
|
encode(_fragment, RESERVED_FRAGMENT, pathEtc);
|
||||||
}
|
}
|
||||||
@@ -378,12 +388,12 @@ std::string URI::getPathAndQuery() const
|
|||||||
{
|
{
|
||||||
std::string pathAndQuery;
|
std::string pathAndQuery;
|
||||||
encode(_path, RESERVED_PATH, pathAndQuery);
|
encode(_path, RESERVED_PATH, pathAndQuery);
|
||||||
if (!_query.empty())
|
if (!_query.empty())
|
||||||
{
|
{
|
||||||
pathAndQuery += '?';
|
pathAndQuery += '?';
|
||||||
encode(_query, RESERVED_QUERY, pathAndQuery);
|
pathAndQuery += _query;
|
||||||
}
|
}
|
||||||
return pathAndQuery;
|
return pathAndQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -438,8 +448,8 @@ void URI::resolve(const URI& relativeURI)
|
|||||||
_query = relativeURI._query;
|
_query = relativeURI._query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_fragment = relativeURI._fragment;
|
_fragment = relativeURI._fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -564,15 +574,15 @@ void URI::getPathSegments(const std::string& path, std::vector<std::string>& seg
|
|||||||
|
|
||||||
void URI::encode(const std::string& str, const std::string& reserved, std::string& encodedStr)
|
void URI::encode(const std::string& str, const std::string& reserved, std::string& encodedStr)
|
||||||
{
|
{
|
||||||
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
|
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
|
||||||
{
|
{
|
||||||
char c = *it;
|
char c = *it;
|
||||||
if (c >= 'a' && c <= 'z' ||
|
if ((c >= 'a' && c <= 'z') ||
|
||||||
c >= 'A' && c <= 'Z' ||
|
(c >= 'A' && c <= 'Z') ||
|
||||||
c >= '0' && c <= '9' ||
|
(c >= '0' && c <= '9') ||
|
||||||
c == '-' || c == '_' ||
|
c == '-' || c == '_' ||
|
||||||
c == '.' || c == '~')
|
c == '.' || c == '~')
|
||||||
{
|
{
|
||||||
encodedStr += c;
|
encodedStr += c;
|
||||||
}
|
}
|
||||||
else if (c <= 0x20 || c >= 0x7F || ILLEGAL.find(c) != std::string::npos || reserved.find(c) != std::string::npos)
|
else if (c <= 0x20 || c >= 0x7F || ILLEGAL.find(c) != std::string::npos || reserved.find(c) != std::string::npos)
|
||||||
@@ -638,11 +648,19 @@ unsigned short URI::getWellKnownPort() const
|
|||||||
else if (_scheme == "nntp")
|
else if (_scheme == "nntp")
|
||||||
return 119;
|
return 119;
|
||||||
else if (_scheme == "ldap")
|
else if (_scheme == "ldap")
|
||||||
return 389;
|
return 389;
|
||||||
else if (_scheme == "https")
|
else if (_scheme == "https")
|
||||||
return 443;
|
return 443;
|
||||||
else
|
else if (_scheme == "rtsp")
|
||||||
return 0;
|
return 554;
|
||||||
|
else if (_scheme == "sip")
|
||||||
|
return 5060;
|
||||||
|
else if (_scheme == "sips")
|
||||||
|
return 5061;
|
||||||
|
else if (_scheme == "xmpp")
|
||||||
|
return 5222;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -707,15 +725,16 @@ void URI::parseHostAndPort(std::string::const_iterator& it, const std::string::c
|
|||||||
{
|
{
|
||||||
if (it == end) return;
|
if (it == end) return;
|
||||||
std::string host;
|
std::string host;
|
||||||
if (*it == '[')
|
if (*it == '[')
|
||||||
{
|
{
|
||||||
// IPv6 address
|
// IPv6 address
|
||||||
while (it != end && *it != ']') host += *it++;
|
++it;
|
||||||
if (it == end) throw SyntaxException("unterminated IPv6 address");
|
while (it != end && *it != ']') host += *it++;
|
||||||
host += *it++;
|
if (it == end) throw SyntaxException("unterminated IPv6 address");
|
||||||
}
|
++it;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
|
{
|
||||||
while (it != end && *it != ':') host += *it++;
|
while (it != end && *it != ':') host += *it++;
|
||||||
}
|
}
|
||||||
if (it != end && *it == ':')
|
if (it != end && *it == ':')
|
||||||
@@ -791,14 +810,14 @@ void URI::mergePath(const std::string& path)
|
|||||||
bool endsWithSlash = *(_path.rbegin()) == '/';
|
bool endsWithSlash = *(_path.rbegin()) == '/';
|
||||||
if (!endsWithSlash && !segments.empty())
|
if (!endsWithSlash && !segments.empty())
|
||||||
segments.pop_back();
|
segments.pop_back();
|
||||||
addLeadingSlash = _path[0] == '/';
|
addLeadingSlash = _path[0] == '/';
|
||||||
}
|
}
|
||||||
getPathSegments(path, segments);
|
getPathSegments(path, segments);
|
||||||
addLeadingSlash = addLeadingSlash || !path.empty() && path[0] == '/';
|
addLeadingSlash = addLeadingSlash || (!path.empty() && path[0] == '/');
|
||||||
bool hasTrailingSlash = !path.empty() && *(path.rbegin()) == '/';
|
bool hasTrailingSlash = (!path.empty() && *(path.rbegin()) == '/');
|
||||||
bool addTrailingSlash = false;
|
bool addTrailingSlash = false;
|
||||||
for (std::vector<std::string>::const_iterator it = segments.begin(); it != segments.end(); ++it)
|
for (std::vector<std::string>::const_iterator it = segments.begin(); it != segments.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == "..")
|
if (*it == "..")
|
||||||
{
|
{
|
||||||
addTrailingSlash = true;
|
addTrailingSlash = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user