Skip to content

Commit

Permalink
Merge pull request microsoft#11 from Esri/mich6984/dont-lowercase-sch…
Browse files Browse the repository at this point in the history
…eme-and-host

Preserve original casing, don't lowercase scheme or host
  • Loading branch information
MikeyNick authored Aug 17, 2022
2 parents c60b35d + a411de9 commit b6dd3c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Release/include/cpprest/base_uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ class uri
/// <returns><c>true</c> if this URI references the local host, <c>false</c> otherwise.</returns>
bool is_host_loopback() const
{
auto host = this->host();
utility::details::inplace_tolower(host);
return !is_empty() &&
((host() == _XPLATSTR("localhost")) || (host().size() > 4 && host().substr(0, 4) == _XPLATSTR("127.")));
((host == _XPLATSTR("localhost")) || (host.size() > 4 && host.substr(0, 4) == _XPLATSTR("127.")));
}

/// <summary>
Expand Down
20 changes: 11 additions & 9 deletions Release/src/uri/uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ struct inner_parse_out
if (scheme_begin)
{
components.m_scheme.assign(scheme_begin, scheme_end);
utility::details::inplace_tolower(components.m_scheme);
}
else
{
Expand All @@ -352,7 +351,6 @@ struct inner_parse_out
if (host_begin)
{
components.m_host.assign(host_begin, host_end);
utility::details::inplace_tolower(components.m_host);
}
else
{
Expand Down Expand Up @@ -476,11 +474,6 @@ utility::string_t uri_components::join()
{
// canonicalize components first

// convert scheme to lowercase
utility::details::inplace_tolower(m_scheme);
// convert host to lowercase
utility::details::inplace_tolower(m_host);

// canonicalize the path to have a leading slash if it's a full uri
if (!m_host.empty() && m_path.empty())
{
Expand Down Expand Up @@ -773,6 +766,15 @@ bool uri::operator==(const uri& other) const
// Each individual URI component must be decoded before performing comparison.
// TFS # 375865

auto this_scheme_lower = this->scheme();
utility::details::inplace_tolower(this_scheme_lower);
auto other_scheme_lower = other.scheme();
utility::details::inplace_tolower(other_scheme_lower);
auto this_host_lower = this->host();
utility::details::inplace_tolower(this_host_lower);
auto other_host_lower = other.host();
utility::details::inplace_tolower(other_host_lower);

if (this->is_empty() && other.is_empty())
{
return true;
Expand All @@ -781,7 +783,7 @@ bool uri::operator==(const uri& other) const
{
return false;
}
else if (this->scheme() != other.scheme())
else if (this_scheme_lower != other_scheme_lower)
{
// scheme is canonicalized to lowercase
return false;
Expand All @@ -790,7 +792,7 @@ bool uri::operator==(const uri& other) const
{
return false;
}
else if (uri::decode(this->host()) != uri::decode(other.host()))
else if (uri::decode(this_host_lower) != uri::decode(other_host_lower))
{
// host is canonicalized to lowercase
return false;
Expand Down
12 changes: 6 additions & 6 deletions Release/tests/functional/uri/constructor_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ SUITE(constructor_tests)
// Tests a variety of different URIs using the examples in RFC 2732
TEST(RFC_2732_examples_string)
{
// The URI parser will make characters lower case
// The URI parser will keep the original casing
uri http1(U("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"));
VERIFY_ARE_EQUAL(U("http"), http1.scheme());
VERIFY_ARE_EQUAL(U("[fedc:ba98:7654:3210:fedc:ba98:7654:3210]"), http1.host());
VERIFY_ARE_EQUAL(U("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"), http1.host());
VERIFY_ARE_EQUAL(80, http1.port());
VERIFY_ARE_EQUAL(U("/index.html"), http1.path());
VERIFY_ARE_EQUAL(U(""), http1.query());

uri http2(U("http://[1080:0:0:0:8:800:200C:417A]/index.html"));
VERIFY_ARE_EQUAL(U("http"), http2.scheme());
VERIFY_ARE_EQUAL(U("[1080:0:0:0:8:800:200c:417a]"), http2.host());
VERIFY_ARE_EQUAL(U("[1080:0:0:0:8:800:200C:417A]"), http2.host());
VERIFY_ARE_EQUAL(0, http2.port());
VERIFY_ARE_EQUAL(U("/index.html"), http2.path());
VERIFY_ARE_EQUAL(U(""), http2.query());
Expand All @@ -164,21 +164,21 @@ SUITE(constructor_tests)

uri http5(U("http://[1080::8:800:200C:417A]/foo"));
VERIFY_ARE_EQUAL(U("http"), http5.scheme());
VERIFY_ARE_EQUAL(U("[1080::8:800:200c:417a]"), http5.host());
VERIFY_ARE_EQUAL(U("[1080::8:800:200C:417A]"), http5.host());
VERIFY_ARE_EQUAL(0, http5.port());
VERIFY_ARE_EQUAL(U("/foo"), http5.path());
VERIFY_ARE_EQUAL(U(""), http5.query());

uri http6(U("http://[::FFFF:129.144.52.38]:80/index.html"));
VERIFY_ARE_EQUAL(U("http"), http6.scheme());
VERIFY_ARE_EQUAL(U("[::ffff:129.144.52.38]"), http6.host());
VERIFY_ARE_EQUAL(U("[::FFFF:129.144.52.38]"), http6.host());
VERIFY_ARE_EQUAL(80, http6.port());
VERIFY_ARE_EQUAL(U("/index.html"), http6.path());
VERIFY_ARE_EQUAL(U(""), http6.query());

uri http7(U("http://[2010:836B:4179::836B:4179]"));
VERIFY_ARE_EQUAL(U("http"), http7.scheme());
VERIFY_ARE_EQUAL(U("[2010:836b:4179::836b:4179]"), http7.host());
VERIFY_ARE_EQUAL(U("[2010:836B:4179::836B:4179]"), http7.host());
VERIFY_ARE_EQUAL(0, http7.port());
VERIFY_ARE_EQUAL(U("/"), http7.path());
VERIFY_ARE_EQUAL(U(""), http7.query());
Expand Down

0 comments on commit b6dd3c2

Please sign in to comment.