Skip to content

Commit fe308d9

Browse files
committed
Fix for microsoft#595
1 parent ca81f1f commit fe308d9

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

Release/src/uri/uri.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,6 @@ namespace
106106
return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == ':';
107107
}
108108

109-
/// <summary>
110-
/// Legal characters in the host portion include:
111-
/// - Any unreserved character
112-
/// - The percent character ('%'), and thus any percent-endcoded octet
113-
/// - The sub-delimiters
114-
/// - ':' (colon)
115-
/// - '[' (open bracket)
116-
/// - ']' (close bracket)
117-
/// </summary>
118-
inline bool is_host_character(int c)
119-
{
120-
return is_unreserved(c) || is_sub_delim(c) || c == '%' || c == ':' || c == '[' || c == ']';
121-
}
122-
123109
/// <summary>
124110
/// Legal characters in the authority portion include:
125111
/// - Any unreserved character
@@ -653,27 +639,28 @@ static int hex_char_digit_to_decimal_char(int hex)
653639
return decimal;
654640
}
655641

656-
utility::string_t uri::decode(const utility::string_t &encoded)
642+
template<class String>
643+
static std::string decode_template(const String& encoded)
657644
{
658-
utf8string raw;
659-
for(auto iter = encoded.begin(); iter != encoded.end(); ++iter)
645+
std::string raw;
646+
for (auto iter = encoded.begin(); iter != encoded.end(); ++iter)
660647
{
661-
if(*iter == _XPLATSTR('%'))
648+
if (*iter == '%')
662649
{
663-
if(++iter == encoded.end())
650+
if (++iter == encoded.end())
664651
{
665652
throw uri_exception("Invalid URI string, two hexadecimal digits must follow '%'");
666653
}
667654
int decimal_value = hex_char_digit_to_decimal_char(static_cast<int>(*iter)) << 4;
668-
if(++iter == encoded.end())
655+
if (++iter == encoded.end())
669656
{
670657
throw uri_exception("Invalid URI string, two hexadecimal digits must follow '%'");
671658
}
672659
decimal_value += hex_char_digit_to_decimal_char(static_cast<int>(*iter));
673660

674661
raw.push_back(static_cast<char>(decimal_value));
675662
}
676-
else if (*iter > CHAR_MAX || *iter < 0)
663+
else if (*iter > 127 || *iter < 0)
677664
{
678665
throw uri_exception("Invalid encoded URI string, must be entirely ascii");
679666
}
@@ -683,7 +670,12 @@ utility::string_t uri::decode(const utility::string_t &encoded)
683670
raw.push_back(static_cast<char>(*iter));
684671
}
685672
}
686-
return to_string_t(raw);
673+
return raw;
674+
}
675+
676+
utility::string_t uri::decode(const utility::string_t &encoded)
677+
{
678+
return to_string_t(decode_template(encoded));
687679
}
688680

689681
std::vector<utility::string_t> uri::split_path(const utility::string_t &path)

0 commit comments

Comments
 (0)