mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
feat: detect invalid tokens
This commit is contained in:
@@ -38,6 +38,15 @@ namespace config
|
|||||||
else
|
else
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool istomlmapdecl(char c)
|
||||||
|
{
|
||||||
|
if (isalnum(c) || c == '-' || c == '_' || c == '.')
|
||||||
|
return (true);
|
||||||
|
else
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
Tokenizer::Tokenizer(char *filename)
|
Tokenizer::Tokenizer(char *filename)
|
||||||
{
|
{
|
||||||
last_token = NO_TOK;
|
last_token = NO_TOK;
|
||||||
@@ -99,7 +108,7 @@ namespace config
|
|||||||
{
|
{
|
||||||
token.type = MAPARRAY_DECL;
|
token.type = MAPARRAY_DECL;
|
||||||
file.get(c);
|
file.get(c);
|
||||||
while (c != ']')
|
while (c != ']' && config::istomlmapdecl(c))
|
||||||
{
|
{
|
||||||
token.value += c;
|
token.value += c;
|
||||||
file.get(c);
|
file.get(c);
|
||||||
@@ -107,7 +116,7 @@ namespace config
|
|||||||
if (c == ']')
|
if (c == ']')
|
||||||
file.get(c);
|
file.get(c);
|
||||||
if (c != ']')
|
if (c != ']')
|
||||||
throw std::logic_error("error in MAPARRAY_DECL");
|
throw InvalidToken("[[" + token.value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -120,7 +129,8 @@ namespace config
|
|||||||
file.get(c);
|
file.get(c);
|
||||||
}
|
}
|
||||||
if (c != ']')
|
if (c != ']')
|
||||||
throw std::logic_error("malformed MAP_DECL");
|
// throw std::logic_error("malformed MAP_DECL");
|
||||||
|
throw InvalidToken(token.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (c == '[')
|
else if (c == '[')
|
||||||
@@ -233,6 +243,16 @@ namespace config
|
|||||||
token.type = NEWLINE;
|
token.type = NEWLINE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (!config::isspace(c) && (c != '\n'))
|
||||||
|
{
|
||||||
|
DBOUT << RED << "[" << c << "]" <<ENDL;
|
||||||
|
token.value += c;
|
||||||
|
file.get(c);
|
||||||
|
}
|
||||||
|
throw InvalidToken(token.value);
|
||||||
|
}
|
||||||
last_token = token.type;
|
last_token = token.type;
|
||||||
|
|
||||||
DBOUT << YELLO << "GOT " << token.value << ", type: " << token.type << ENDL;
|
DBOUT << YELLO << "GOT " << token.value << ", type: " << token.type << ENDL;
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ namespace config
|
|||||||
|
|
||||||
bool istomlkey(char c);
|
bool istomlkey(char c);
|
||||||
|
|
||||||
|
bool istomlmapdecl(char c);
|
||||||
|
|
||||||
class Tokenizer
|
class Tokenizer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user