mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
#2818: Add getSpecifiedPort() method to URI
This commit is contained in:
parent
8d227dc8d3
commit
fafa92d353
@ -31,7 +31,7 @@ class Path;
|
||||
|
||||
class Foundation_API URI
|
||||
/// A Uniform Resource Identifier, as specified in RFC 3986.
|
||||
///
|
||||
///
|
||||
/// The URI class provides methods for building URIs from their
|
||||
/// parts, as well as for splitting URIs into their parts.
|
||||
/// Furthermore, the class provides methods for resolving
|
||||
@ -59,14 +59,14 @@ public:
|
||||
explicit URI(const std::string& uri);
|
||||
/// Parses an URI from the given string. Throws a
|
||||
/// SyntaxException if the uri is not valid.
|
||||
|
||||
|
||||
explicit URI(const char* uri);
|
||||
/// Parses an URI from the given string. Throws a
|
||||
/// SyntaxException if the uri is not valid.
|
||||
|
||||
|
||||
URI(const std::string& scheme, const std::string& pathEtc);
|
||||
/// Creates an URI from its parts.
|
||||
|
||||
|
||||
URI(const std::string& scheme, const std::string& authority, const std::string& pathEtc);
|
||||
/// Creates an URI from its parts.
|
||||
|
||||
@ -81,7 +81,7 @@ public:
|
||||
|
||||
URI(URI&& uri) noexcept;
|
||||
/// Move constructor.
|
||||
|
||||
|
||||
URI(const URI& baseURI, const std::string& relativeURI);
|
||||
/// Creates an URI from a base URI and a relative URI, according to
|
||||
/// the algorithm in section 5.2 of RFC 3986.
|
||||
@ -94,12 +94,12 @@ public:
|
||||
|
||||
~URI();
|
||||
/// Destroys the URI.
|
||||
|
||||
|
||||
URI& operator = (const URI& uri);
|
||||
/// Assignment operator.
|
||||
|
||||
URI& operator = (URI&& uri) noexcept;
|
||||
/// Move assignment.
|
||||
/// Move assignment.
|
||||
|
||||
URI& operator = (const std::string& uri);
|
||||
/// Parses and assigns an URI from the given string. Throws a
|
||||
@ -108,41 +108,41 @@ public:
|
||||
URI& operator = (const char* uri);
|
||||
/// Parses and assigns an URI from the given string. Throws a
|
||||
/// SyntaxException if the uri is not valid.
|
||||
|
||||
|
||||
void swap(URI& uri);
|
||||
/// Swaps the URI with another one.
|
||||
|
||||
/// Swaps the URI with another one.
|
||||
|
||||
void clear();
|
||||
/// Clears all parts of the URI.
|
||||
|
||||
|
||||
std::string toString() const;
|
||||
/// Returns a string representation of the URI.
|
||||
///
|
||||
/// Characters in the path, query and fragment parts will be
|
||||
/// Characters in the path, query and fragment parts will be
|
||||
/// percent-encoded as necessary.
|
||||
|
||||
|
||||
const std::string& getScheme() const;
|
||||
/// Returns the scheme part of the URI.
|
||||
|
||||
|
||||
void setScheme(const std::string& scheme);
|
||||
/// Sets the scheme part of the URI. The given scheme
|
||||
/// is converted to lower-case.
|
||||
///
|
||||
/// A list of registered URI schemes can be found
|
||||
/// at <http://www.iana.org/assignments/uri-schemes>.
|
||||
|
||||
|
||||
const std::string& getUserInfo() const;
|
||||
/// Returns the user-info part of the URI.
|
||||
|
||||
|
||||
void setUserInfo(const std::string& userInfo);
|
||||
/// Sets the user-info part of the URI.
|
||||
|
||||
|
||||
const std::string& getHost() const;
|
||||
/// Returns the host part of the URI.
|
||||
|
||||
|
||||
void setHost(const std::string& host);
|
||||
/// Sets the host part of the URI.
|
||||
|
||||
|
||||
unsigned short getPort() const;
|
||||
/// Returns the port number part of the URI.
|
||||
///
|
||||
@ -150,39 +150,45 @@ public:
|
||||
/// well-known port number (e.g., 80 for http) for
|
||||
/// the given scheme is returned if it is known.
|
||||
/// Otherwise, 0 is returned.
|
||||
|
||||
|
||||
void setPort(unsigned short port);
|
||||
/// Sets the port number part of the URI.
|
||||
|
||||
|
||||
unsigned short getSpecifiedPort() const;
|
||||
/// Returns the port number part of the URI.
|
||||
///
|
||||
/// If no explicit port number has been specified,
|
||||
/// returns 0.
|
||||
|
||||
std::string getAuthority() const;
|
||||
/// Returns the authority part (userInfo, host and port)
|
||||
/// of the URI.
|
||||
/// of the URI.
|
||||
///
|
||||
/// If the port number is a well-known port
|
||||
/// number for the given scheme (e.g., 80 for http), it
|
||||
/// is not included in the authority.
|
||||
|
||||
|
||||
void setAuthority(const std::string& authority);
|
||||
/// Parses the given authority part for the URI and sets
|
||||
/// the user-info, host, port components accordingly.
|
||||
|
||||
|
||||
const std::string& getPath() const;
|
||||
/// Returns the decoded path part of the URI.
|
||||
|
||||
|
||||
void setPath(const std::string& path);
|
||||
/// Sets the path part of the URI.
|
||||
|
||||
|
||||
std::string getQuery() const;
|
||||
/// Returns the decoded query part of the URI.
|
||||
///
|
||||
/// Note that encoded ampersand characters ('&', "%26")
|
||||
/// will be decoded, which could cause ambiguities if the query
|
||||
/// Note that encoded ampersand characters ('&', "%26")
|
||||
/// will be decoded, which could cause ambiguities if the query
|
||||
/// string contains multiple parameters and a parameter name
|
||||
/// or value contains an ampersand as well.
|
||||
/// In such a case it's better to use getRawQuery() or
|
||||
/// getQueryParameters().
|
||||
|
||||
void setQuery(const std::string& query);
|
||||
|
||||
void setQuery(const std::string& query);
|
||||
/// Sets the query part of the URI.
|
||||
///
|
||||
/// The query string will be percent-encoded. If the query
|
||||
@ -192,28 +198,28 @@ public:
|
||||
/// characters in the query will not be encoded. This could
|
||||
/// lead to ambiguity issues if the query string contains multiple
|
||||
/// name-value parameters separated by ampersand, and if any
|
||||
/// name or value also contains an ampersand. In such a
|
||||
/// name or value also contains an ampersand. In such a
|
||||
/// case, it's better to use setRawQuery() with a properly
|
||||
/// percent-encoded query string, or use addQueryParameter()
|
||||
/// or setQueryParameters(), which take care of appropriate
|
||||
/// or setQueryParameters(), which take care of appropriate
|
||||
/// percent encoding of parameter names and values.
|
||||
|
||||
void addQueryParameter(const std::string& param, const std::string& val = "");
|
||||
/// Adds "param=val" to the query; "param" may not be empty.
|
||||
/// If val is empty, only '=' is appended to the parameter.
|
||||
///
|
||||
///
|
||||
/// In addition to regular encoding, function also encodes '&' and '=',
|
||||
/// if found in param or val.
|
||||
|
||||
const std::string& getRawQuery() const;
|
||||
/// Returns the query string in raw form, which usually
|
||||
/// means percent encoded.
|
||||
|
||||
void setRawQuery(const std::string& query);
|
||||
|
||||
void setRawQuery(const std::string& query);
|
||||
/// Sets the query part of the URI.
|
||||
///
|
||||
/// The given query string must be properly percent-encoded.
|
||||
|
||||
|
||||
QueryParameters getQueryParameters() const;
|
||||
/// Returns the decoded query string parameters as a vector
|
||||
/// of name-value pairs.
|
||||
@ -226,19 +232,19 @@ public:
|
||||
|
||||
const std::string& getFragment() const;
|
||||
/// Returns the fragment part of the URI.
|
||||
|
||||
|
||||
void setFragment(const std::string& fragment);
|
||||
/// Sets the fragment part of the URI.
|
||||
|
||||
|
||||
void setPathEtc(const std::string& pathEtc);
|
||||
/// Sets the path, query and fragment parts of the URI.
|
||||
|
||||
|
||||
std::string getPathEtc() const;
|
||||
/// Returns the encoded path, query and fragment parts of the URI.
|
||||
|
||||
|
||||
std::string getPathAndQuery() const;
|
||||
/// Returns the encoded path and query parts of the URI.
|
||||
|
||||
/// Returns the encoded path and query parts of the URI.
|
||||
|
||||
void resolve(const std::string& relativeURI);
|
||||
/// Resolves the given relative URI against the base URI.
|
||||
/// See section 5.2 of RFC 3986 for the algorithm used.
|
||||
@ -253,10 +259,10 @@ public:
|
||||
/// A relative reference does not contain a scheme identifier.
|
||||
/// Relative references are usually resolved against an absolute
|
||||
/// base reference.
|
||||
|
||||
|
||||
bool empty() const;
|
||||
/// Returns true if the URI is empty, false otherwise.
|
||||
|
||||
|
||||
bool operator == (const URI& uri) const;
|
||||
/// Returns true if both URIs are identical, false otherwise.
|
||||
///
|
||||
@ -273,22 +279,22 @@ public:
|
||||
bool operator != (const std::string& uri) const;
|
||||
/// Parses the given URI and returns true if both URIs are identical,
|
||||
/// false otherwise.
|
||||
|
||||
|
||||
void normalize();
|
||||
/// Normalizes the URI by removing all but leading . and .. segments from the path.
|
||||
///
|
||||
/// If the first path segment in a relative path contains a colon (:),
|
||||
/// such as in a Windows path containing a drive letter, a dot segment (./)
|
||||
/// If the first path segment in a relative path contains a colon (:),
|
||||
/// such as in a Windows path containing a drive letter, a dot segment (./)
|
||||
/// is prepended in accordance with section 3.3 of RFC 3986.
|
||||
|
||||
|
||||
void getPathSegments(std::vector<std::string>& segments);
|
||||
/// Places the single path segments (delimited by slashes) into the
|
||||
/// given vector.
|
||||
|
||||
|
||||
static void encode(const std::string& str, const std::string& reserved, std::string& encodedStr);
|
||||
/// URI-encodes the given string by escaping reserved and non-ASCII
|
||||
/// characters. The encoded string is appended to encodedStr.
|
||||
|
||||
|
||||
static void decode(const std::string& str, std::string& decodedStr, bool plusAsSpace = false);
|
||||
/// URI-decodes the given string by replacing percent-encoded
|
||||
/// characters with the actual character. The decoded string
|
||||
@ -300,15 +306,15 @@ public:
|
||||
protected:
|
||||
bool equals(const URI& uri) const;
|
||||
/// Returns true if both uri's are equivalent.
|
||||
|
||||
|
||||
bool isWellKnownPort() const;
|
||||
/// Returns true if the URI's port number is a well-known one
|
||||
/// (for example, 80, if the scheme is http).
|
||||
|
||||
|
||||
unsigned short getWellKnownPort() const;
|
||||
/// Returns the well-known port number for the URI's scheme,
|
||||
/// or 0 if the port number is not known.
|
||||
|
||||
|
||||
void parse(const std::string& uri);
|
||||
/// Parses and assigns an URI from the given string. Throws a
|
||||
/// SyntaxException if the uri is not valid.
|
||||
@ -349,7 +355,7 @@ protected:
|
||||
static const std::string RESERVED_QUERY_PARAM;
|
||||
static const std::string RESERVED_FRAGMENT;
|
||||
static const std::string ILLEGAL;
|
||||
|
||||
|
||||
private:
|
||||
std::string _scheme;
|
||||
std::string _userInfo;
|
||||
@ -368,44 +374,50 @@ inline const std::string& URI::getScheme() const
|
||||
{
|
||||
return _scheme;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline const std::string& URI::getUserInfo() const
|
||||
{
|
||||
return _userInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline const std::string& URI::getHost() const
|
||||
{
|
||||
return _host;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline const std::string& URI::getPath() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline const std::string& URI::getRawQuery() const
|
||||
{
|
||||
return _query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline const std::string& URI::getFragment() const
|
||||
{
|
||||
return _fragment;
|
||||
}
|
||||
|
||||
|
||||
inline unsigned short URI::getSpecifiedPort() const
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
|
||||
|
||||
inline void swap(URI& u1, URI& u2)
|
||||
{
|
||||
u1.swap(u2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
@ -49,19 +49,18 @@ URI::URI(const char* uri):
|
||||
parse(std::string(uri));
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI::URI(const std::string& scheme, const std::string& pathEtc):
|
||||
_scheme(scheme),
|
||||
_port(0)
|
||||
{
|
||||
toLowerInPlace(_scheme);
|
||||
_port = getWellKnownPort();
|
||||
std::string::const_iterator beg = pathEtc.begin();
|
||||
std::string::const_iterator end = pathEtc.end();
|
||||
parsePathEtc(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI::URI(const std::string& scheme, const std::string& authority, const std::string& pathEtc):
|
||||
_scheme(scheme)
|
||||
{
|
||||
@ -181,7 +180,7 @@ URI& URI::operator = (URI&& uri) noexcept
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI& URI::operator = (const std::string& uri)
|
||||
{
|
||||
clear();
|
||||
@ -268,18 +267,16 @@ void URI::setScheme(const std::string& scheme)
|
||||
{
|
||||
_scheme = scheme;
|
||||
toLowerInPlace(_scheme);
|
||||
if (_port == 0)
|
||||
_port = getWellKnownPort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setUserInfo(const std::string& userInfo)
|
||||
{
|
||||
_userInfo.clear();
|
||||
decode(userInfo, _userInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setHost(const std::string& host)
|
||||
{
|
||||
_host = host;
|
||||
@ -300,7 +297,7 @@ void URI::setPort(unsigned short port)
|
||||
_port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string URI::getAuthority() const
|
||||
{
|
||||
std::string auth;
|
||||
@ -324,7 +321,7 @@ std::string URI::getAuthority() const
|
||||
return auth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setAuthority(const std::string& authority)
|
||||
{
|
||||
_userInfo.clear();
|
||||
@ -335,14 +332,14 @@ void URI::setAuthority(const std::string& authority)
|
||||
parseAuthority(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setPath(const std::string& path)
|
||||
{
|
||||
_path.clear();
|
||||
decode(path, _path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setRawQuery(const std::string& query)
|
||||
{
|
||||
_query = query;
|
||||
@ -384,7 +381,7 @@ URI::QueryParameters URI::getQueryParameters() const
|
||||
std::string value;
|
||||
while (it != end && *it != '=' && *it != '&')
|
||||
{
|
||||
if (*it == '+')
|
||||
if (*it == '+')
|
||||
name += ' ';
|
||||
else
|
||||
name += *it;
|
||||
@ -395,7 +392,7 @@ URI::QueryParameters URI::getQueryParameters() const
|
||||
++it;
|
||||
while (it != end && *it != '&')
|
||||
{
|
||||
if (*it == '+')
|
||||
if (*it == '+')
|
||||
value += ' ';
|
||||
else
|
||||
value += *it;
|
||||
@ -407,7 +404,7 @@ URI::QueryParameters URI::getQueryParameters() const
|
||||
URI::decode(name, decodedName);
|
||||
URI::decode(value, decodedValue);
|
||||
result.push_back(std::make_pair(decodedName, decodedValue));
|
||||
if (it != end && *it == '&') ++it;
|
||||
if (it != end && *it == '&') ++it;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -440,7 +437,7 @@ void URI::setPathEtc(const std::string& pathEtc)
|
||||
parsePathEtc(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string URI::getPathEtc() const
|
||||
{
|
||||
std::string pathEtc;
|
||||
@ -471,7 +468,7 @@ std::string URI::getPathAndQuery() const
|
||||
return pathAndQuery;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::resolve(const std::string& relativeURI)
|
||||
{
|
||||
URI parsedURI(relativeURI);
|
||||
@ -524,7 +521,7 @@ void URI::resolve(const URI& relativeURI)
|
||||
}
|
||||
}
|
||||
}
|
||||
_fragment = relativeURI._fragment;
|
||||
_fragment = relativeURI._fragment;
|
||||
}
|
||||
|
||||
|
||||
@ -539,7 +536,7 @@ bool URI::empty() const
|
||||
return _scheme.empty() && _host.empty() && _path.empty() && _query.empty() && _fragment.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool URI::operator == (const URI& uri) const
|
||||
{
|
||||
return equals(uri);
|
||||
@ -577,7 +574,7 @@ bool URI::equals(const URI& uri) const
|
||||
&& _fragment == uri._fragment;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::normalize()
|
||||
{
|
||||
removeDotSegments(!isRelative());
|
||||
@ -587,7 +584,7 @@ void URI::normalize()
|
||||
void URI::removeDotSegments(bool removeLeading)
|
||||
{
|
||||
if (_path.empty()) return;
|
||||
|
||||
|
||||
bool leadingSlash = *(_path.begin()) == '/';
|
||||
bool trailingSlash = *(_path.rbegin()) == '/';
|
||||
std::vector<std::string> segments;
|
||||
@ -651,10 +648,10 @@ void URI::encode(const std::string& str, const std::string& reserved, std::strin
|
||||
{
|
||||
for (auto c: str)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
if ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
c == '-' || c == '_' ||
|
||||
c == '-' || c == '_' ||
|
||||
c == '.' || c == '~')
|
||||
{
|
||||
encodedStr += c;
|
||||
@ -668,7 +665,7 @@ void URI::encode(const std::string& str, const std::string& reserved, std::strin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::decode(const std::string& str, std::string& decodedStr, bool plusAsSpace)
|
||||
{
|
||||
bool inQuery = false;
|
||||
@ -782,7 +779,7 @@ void URI::parse(const std::string& uri)
|
||||
}
|
||||
parsePathEtc(it, end);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
it = uri.begin();
|
||||
parsePathEtc(it, end);
|
||||
@ -842,9 +839,9 @@ void URI::parseHostAndPort(std::string::const_iterator& it, const std::string::c
|
||||
else
|
||||
throw URISyntaxException("bad or invalid port number", port);
|
||||
}
|
||||
else _port = getWellKnownPort();
|
||||
else _port = 0;
|
||||
}
|
||||
else _port = getWellKnownPort();
|
||||
else _port = 0;
|
||||
_host = host;
|
||||
toLowerInPlace(_host);
|
||||
}
|
||||
@ -872,7 +869,7 @@ void URI::parsePathEtc(std::string::const_iterator& it, const std::string::const
|
||||
{
|
||||
++it;
|
||||
parseFragment(it, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -944,7 +941,7 @@ void URI::buildPath(const std::vector<std::string>& segments, bool leadingSlash,
|
||||
else _path += '/';
|
||||
_path.append(s);
|
||||
}
|
||||
if (trailingSlash)
|
||||
if (trailingSlash)
|
||||
_path += '/';
|
||||
}
|
||||
|
||||
|
@ -40,58 +40,60 @@ void URITest::testConstruction()
|
||||
assertTrue (uri.getPath().empty());
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri.setScheme("ftp");
|
||||
assertTrue (uri.getScheme() == "ftp");
|
||||
assertTrue (uri.getPort() == 21);
|
||||
|
||||
|
||||
uri.setScheme("HTTP");
|
||||
assertTrue (uri.getScheme() == "http");
|
||||
|
||||
|
||||
uri.setAuthority("www.appinf.com");
|
||||
assertTrue (uri.getAuthority() == "www.appinf.com");
|
||||
assertTrue (uri.getPort() == 80);
|
||||
|
||||
assertTrue (uri.getSpecifiedPort() == 0);
|
||||
|
||||
uri.setAuthority("user@services.appinf.com:8000");
|
||||
assertTrue (uri.getUserInfo() == "user");
|
||||
assertTrue (uri.getHost() == "services.appinf.com");
|
||||
assertTrue (uri.getPort() == 8000);
|
||||
|
||||
assertTrue (uri.getSpecifiedPort() == 8000);
|
||||
|
||||
uri.setPath("/index.html");
|
||||
assertTrue (uri.getPath() == "/index.html");
|
||||
|
||||
|
||||
uri.setPath("/file%20with%20spaces.html");
|
||||
assertTrue (uri.getPath() == "/file with spaces.html");
|
||||
|
||||
|
||||
uri.setPathEtc("/query.cgi?query=foo");
|
||||
assertTrue (uri.getPath() == "/query.cgi");
|
||||
assertTrue (uri.getQuery() == "query=foo");
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (uri.getPathEtc() == "/query.cgi?query=foo");
|
||||
assertTrue (uri.getPathAndQuery() == "/query.cgi?query=foo");
|
||||
|
||||
|
||||
uri.setPathEtc("/query.cgi?query=bar#frag");
|
||||
assertTrue (uri.getPath() == "/query.cgi");
|
||||
assertTrue (uri.getQuery() == "query=bar");
|
||||
assertTrue (uri.getFragment() == "frag");
|
||||
assertTrue (uri.getPathEtc() == "/query.cgi?query=bar#frag");
|
||||
assertTrue (uri.getPathAndQuery() == "/query.cgi?query=bar");
|
||||
|
||||
|
||||
uri.setQuery("query=test");
|
||||
assertTrue (uri.getQuery() == "query=test");
|
||||
|
||||
|
||||
uri.setFragment("result");
|
||||
assertTrue (uri.getFragment() == "result");
|
||||
|
||||
|
||||
URI uri2("file", "/home/guenter/foo.bar");
|
||||
assertTrue (uri2.getScheme() == "file");
|
||||
assertTrue (uri2.getPath() == "/home/guenter/foo.bar");
|
||||
|
||||
|
||||
URI uri3("http", "www.appinf.com", "/index.html");
|
||||
assertTrue (uri3.getScheme() == "http");
|
||||
assertTrue (uri3.getAuthority() == "www.appinf.com");
|
||||
assertTrue (uri3.getPath() == "/index.html");
|
||||
|
||||
|
||||
URI uri4("http", "www.appinf.com:8000", "/index.html");
|
||||
assertTrue (uri4.getScheme() == "http");
|
||||
assertTrue (uri4.getAuthority() == "www.appinf.com:8000");
|
||||
@ -110,6 +112,7 @@ void URITest::testConstruction()
|
||||
assertTrue (uri6.getUserInfo() == "user");
|
||||
assertTrue (uri6.getHost() == "www.appinf.com");
|
||||
assertTrue (uri6.getPort() == 80);
|
||||
assertTrue (uri6.getSpecifiedPort() == 80);
|
||||
assertTrue (uri6.getAuthority() == "user@www.appinf.com");
|
||||
assertTrue (uri6.getPath() == "/index.html");
|
||||
|
||||
@ -118,9 +121,10 @@ void URITest::testConstruction()
|
||||
assertTrue (uri7.getUserInfo() == "user");
|
||||
assertTrue (uri7.getHost() == "www.appinf.com");
|
||||
assertTrue (uri7.getPort() == 80);
|
||||
assertTrue (uri7.getSpecifiedPort() == 0);
|
||||
assertTrue (uri7.getAuthority() == "user@www.appinf.com");
|
||||
assertTrue (uri7.getPath() == "/index.html");
|
||||
|
||||
|
||||
URI uri8("http", "www.appinf.com", "/index.html", "query=test");
|
||||
assertTrue (uri8.getScheme() == "http");
|
||||
assertTrue (uri8.getAuthority() == "www.appinf.com");
|
||||
@ -150,9 +154,10 @@ void URITest::testConstruction()
|
||||
assertTrue (uri10.getUserInfo().empty());
|
||||
assertTrue (uri10.getHost() == "2001:db8::7");
|
||||
assertTrue (uri10.getPort() == 389);
|
||||
assertTrue (uri10.getSpecifiedPort() == 0);
|
||||
assertTrue (uri10.getAuthority() == "[2001:db8::7]");
|
||||
assertTrue (uri10.getPathEtc() == "/c=GB?objectClass?one");
|
||||
|
||||
|
||||
URI uri11("http", "www.appinf.com", "/index.html?query=test#fragment");
|
||||
assertTrue (uri11.getScheme() == "http");
|
||||
assertTrue (uri11.getAuthority() == "www.appinf.com");
|
||||
@ -180,7 +185,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "ftp://anonymous@ftp.appinf.com/pub/";
|
||||
assertTrue (uri.getScheme() == "ftp");
|
||||
assertTrue (uri.getUserInfo() == "anonymous");
|
||||
@ -201,7 +206,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment() == "top");
|
||||
assertTrue (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all";
|
||||
assertTrue (uri.getScheme() == "http");
|
||||
assertTrue (uri.getHost() == "www.appinf.com");
|
||||
@ -219,7 +224,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery() == "keyword=test&scope=all");
|
||||
assertTrue (uri.getFragment() == "result");
|
||||
assertTrue (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result";
|
||||
assertTrue (uri.getScheme() == "http");
|
||||
assertTrue (uri.getHost() == "www.appinf.com");
|
||||
@ -228,7 +233,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery() == "keyword=test encoded&scope=all");
|
||||
assertTrue (uri.getFragment() == "result");
|
||||
assertTrue (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
|
||||
assertTrue (uri.getScheme() == "ldap");
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -238,7 +243,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getPath() == "/c=GB");
|
||||
assertTrue (uri.getQuery() == "objectClass?one");
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "mailto:John.Doe@example.com";
|
||||
assertTrue (uri.getScheme() == "mailto");
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -248,7 +253,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getPath() == "John.Doe@example.com");
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "tel:+1-816-555-1212";
|
||||
assertTrue (uri.getScheme() == "tel");
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -258,7 +263,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getPath() == "+1-816-555-1212");
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "telnet://192.0.2.16:80";
|
||||
assertTrue (uri.getScheme() == "telnet");
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -268,7 +273,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getPath().empty());
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2";
|
||||
assertTrue (uri.getScheme() == "urn");
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -278,7 +283,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getPath() == "oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
@ -289,9 +294,9 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (uri.empty());
|
||||
|
||||
|
||||
// relative references
|
||||
|
||||
|
||||
uri = "/foo/bar";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
@ -346,8 +351,8 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment() == "frag");
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
uri = "?query=test";
|
||||
|
||||
uri = "?query=test";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -358,7 +363,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
uri = "?query=test#frag";
|
||||
uri = "?query=test#frag";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -368,8 +373,8 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery() == "query=test");
|
||||
assertTrue (uri.getFragment() == "frag");
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
uri = "#frag";
|
||||
|
||||
uri = "#frag";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -380,7 +385,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getFragment() == "frag");
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
uri = "#";
|
||||
uri = "#";
|
||||
assertTrue (uri.getScheme().empty());
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
assertTrue (uri.getUserInfo().empty());
|
||||
@ -390,7 +395,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
|
||||
uri = "file:///a/b/c";
|
||||
assertTrue (uri.getScheme() == "file");
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
@ -412,7 +417,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
assertTrue (uri.getScheme() == "file");
|
||||
assertTrue (uri.getAuthority().empty());
|
||||
@ -434,7 +439,7 @@ void URITest::testParse()
|
||||
assertTrue (uri.getQuery().empty());
|
||||
assertTrue (uri.getFragment().empty());
|
||||
assertTrue (uri.isRelative());
|
||||
|
||||
|
||||
uri = "ws://www.appinf.com/ws";
|
||||
assertTrue (uri.getScheme() == "ws");
|
||||
assertTrue (uri.getPort() == 80);
|
||||
@ -452,42 +457,42 @@ void URITest::testToString()
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "ftp://anonymous@ftp.appinf.com/pub/";
|
||||
assertTrue (uri.toString() == "ftp://anonymous@ftp.appinf.com/pub/");
|
||||
|
||||
uri = "https://www.appinf.com/index.html#top";
|
||||
assertTrue (uri.toString() == "https://www.appinf.com/index.html#top");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all";
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test&scope=all");
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all#result";
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test&scope=all#result");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result";
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
|
||||
|
||||
uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
|
||||
assertTrue (uri.toString() == "ldap://[2001:db8::7]/c=GB?objectClass?one");
|
||||
|
||||
|
||||
uri = "mailto:John.Doe@example.com";
|
||||
assertTrue (uri.toString() == "mailto:John.Doe@example.com");
|
||||
|
||||
|
||||
uri = "tel:+1-816-555-1212";
|
||||
assertTrue (uri.toString() == "tel:+1-816-555-1212");
|
||||
|
||||
|
||||
uri = "telnet://192.0.2.16:80";
|
||||
assertTrue (uri.toString() == "telnet://192.0.2.16:80");
|
||||
|
||||
|
||||
uri = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2";
|
||||
assertTrue (uri.toString() == "urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
|
||||
|
||||
uri = "";
|
||||
assertTrue (uri.toString() == "");
|
||||
|
||||
// relative references
|
||||
|
||||
|
||||
uri = "/foo/bar";
|
||||
assertTrue (uri.toString() == "/foo/bar");
|
||||
|
||||
@ -505,31 +510,31 @@ void URITest::testToString()
|
||||
|
||||
uri = "index.html#frag";
|
||||
assertTrue (uri.toString() == "index.html#frag");
|
||||
|
||||
uri = "?query=test";
|
||||
|
||||
uri = "?query=test";
|
||||
assertTrue (uri.toString() == "?query=test");
|
||||
|
||||
uri = "?query=test#frag";
|
||||
uri = "?query=test#frag";
|
||||
assertTrue (uri.toString() == "?query=test#frag");
|
||||
|
||||
uri = "#frag";
|
||||
|
||||
uri = "#frag";
|
||||
assertTrue (uri.toString() == "#frag");
|
||||
|
||||
uri = "#";
|
||||
uri = "#";
|
||||
assertTrue (uri.toString() == "");
|
||||
|
||||
|
||||
uri = "file:///a/b/c";
|
||||
assertTrue (uri.toString() == "file:///a/b/c");
|
||||
|
||||
|
||||
uri = "file://localhost/a/b/c";
|
||||
assertTrue (uri.toString() == "file://localhost/a/b/c");
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
assertTrue (uri.toString() == "file:///c:/Windows/system32/");
|
||||
|
||||
uri = "./c:/Windows/system32/";
|
||||
assertTrue (uri.toString() == "./c:/Windows/system32/");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com";
|
||||
uri.setRawQuery("query=test");
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/?query=test");
|
||||
@ -543,19 +548,19 @@ void URITest::testCompare()
|
||||
assertTrue (uri1 == uri2);
|
||||
assertTrue (uri1 == "http://www.appinf.com:");
|
||||
assertTrue (uri1 != "http://www.google.com");
|
||||
|
||||
|
||||
uri1 = "/foo/bar";
|
||||
assertTrue (uri1 == "/foo/bar");
|
||||
assertTrue (uri1 != "/foo/baz");
|
||||
|
||||
|
||||
uri1 = "?query";
|
||||
assertTrue (uri1 == "?query");
|
||||
assertTrue (uri1 != "?query2");
|
||||
|
||||
|
||||
uri1 = "#frag";
|
||||
assertTrue (uri1 == "#frag");
|
||||
assertTrue (uri1 != "#frag2");
|
||||
|
||||
|
||||
uri1 = "/index.html#frag";
|
||||
assertTrue (uri1 == "/index.html#frag");
|
||||
assertTrue (uri1 != "/index.html");
|
||||
@ -567,15 +572,15 @@ void URITest::testNormalize()
|
||||
URI uri("http://www.appinf.com");
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "http://www.appinf.com");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/foo/bar/./index.html";
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/foo/bar/index.html");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/foo/bar/../index.html";
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/foo/index.html");
|
||||
@ -615,7 +620,7 @@ void URITest::testNormalize()
|
||||
uri = "http://www.appinf.com/../foo/../";
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
uri.normalize();
|
||||
assertTrue (uri.toString() == "file:///c:/Windows/system32/");
|
||||
@ -630,13 +635,13 @@ void URITest::testNormalize()
|
||||
void URITest::testResolve()
|
||||
{
|
||||
URI uri("http://www.appinf.com");
|
||||
|
||||
|
||||
uri.resolve("/index.html");
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/index.html");
|
||||
|
||||
|
||||
uri.resolve("#frag");
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/index.html#frag");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/html";
|
||||
uri.resolve("../images/foo.gif");
|
||||
assertTrue (uri.toString() == "http://www.appinf.com/images/foo.gif");
|
||||
@ -664,7 +669,7 @@ void URITest::testResolve()
|
||||
uri = "/a/b/c/d/e";
|
||||
uri.resolve("./../../f/./g");
|
||||
assertTrue (uri.toString() == "/a/b/f/g");
|
||||
|
||||
|
||||
uri = "/a/b/../c/";
|
||||
uri.resolve("../d");
|
||||
assertTrue (uri.toString() == "/a/d");
|
||||
@ -704,7 +709,7 @@ void URITest::testResolve()
|
||||
uri = "http://www.appinf.com/html/";
|
||||
uri.resolve("http://www.google.com/");
|
||||
assertTrue (uri.toString() == "http://www.google.com/");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
URI uri2(uri, "index.html");
|
||||
assertTrue (uri2.toString() == "http://www.appinf.com/index.html");
|
||||
@ -719,7 +724,7 @@ void URITest::testSwap()
|
||||
{
|
||||
URI uri1("http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
URI uri2("mailto:John.Doe@example.com");
|
||||
|
||||
|
||||
uri1.swap(uri2);
|
||||
assertTrue (uri1.toString() == "mailto:John.Doe@example.com");
|
||||
assertTrue (uri2.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
@ -792,11 +797,11 @@ void URITest::testEncodeDecode()
|
||||
str = "";
|
||||
URI::encode("http://google.com/search?q=hello+world#frag ment", "", str);
|
||||
assertTrue (str == "http://google.com/search?q=hello+world#frag%20ment");
|
||||
|
||||
|
||||
str = "";
|
||||
URI::decode("http://google.com/search?q=hello+world#frag%20ment", str, true);
|
||||
assertTrue (str == "http://google.com/search?q=hello world#frag ment");
|
||||
|
||||
|
||||
str = "";
|
||||
URI::decode("http://google.com/search?q=hello%2Bworld#frag%20ment", str);
|
||||
assertTrue (str == "http://google.com/search?q=hello+world#frag ment");
|
||||
@ -812,7 +817,7 @@ void URITest::testFromPath()
|
||||
Path path2("/var/www/site/with space.html", Path::PATH_UNIX);
|
||||
URI uri2(path2);
|
||||
assertTrue (uri2.toString() == "file:///var/www/site/with%20space.html");
|
||||
|
||||
|
||||
Path path3("c:\\www\\index.html", Path::PATH_WINDOWS);
|
||||
URI uri3(path3);
|
||||
assertTrue (uri3.toString() == "file:///c:/www/index.html");
|
||||
|
Loading…
Reference in New Issue
Block a user