Check if we got a reserved char on url for domain and top level domain

This commit is contained in:
Guillaume Tassery 2019-04-23 12:56:24 +07:00
parent c938935766
commit 3639f03bc6

View File

@ -31,7 +31,7 @@ static inline bool isUnsafeCharUrl(char c)
return false;
}
static inline bool isEndOfUrl(char c)
static inline bool isCharEndOfUrl(char c)
{
switch (c)
{
@ -44,6 +44,22 @@ static inline bool isEndOfUrl(char c)
return false;
}
static inline bool isReservedCharUrl(char c)
{
switch (c)
{
case ';':
case '/':
case '?':
case ':':
case '@':
case '=':
case '&':
return true;
}
return false;
}
/// Extracts host from given url.
inline StringRef getURLHost(const char * data, size_t size)
{
@ -82,13 +98,13 @@ inline StringRef getURLHost(const char * data, size_t size)
start_of_host = pos + 1;
else if (*pos == '.')
{
if (pos + 1 == end || isEndOfUrl(*(pos + 1)))
if (pos + 1 == end || isCharEndOfUrl(*(pos + 1)))
return StringRef{};
has_dot_delimiter = true;
}
else if (isEndOfUrl(*pos))
break;
else if (isUnsafeCharUrl(*pos))
else if (isUnsafeCharUrl(*pos) || isReservedCharUrl(*pos))
return StringRef{};
}