From f6837bf8d5fe7e9b9ec99652bf108f08a8784ff4 Mon Sep 17 00:00:00 2001 From: whaffman Date: Fri, 31 Oct 2025 10:04:51 +0100 Subject: [PATCH] feat: validate directive has one semicolon in addDirective method --- webserv/config/AConfig.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/webserv/config/AConfig.cpp b/webserv/config/AConfig.cpp index d4a27e4..623f3b3 100644 --- a/webserv/config/AConfig.cpp +++ b/webserv/config/AConfig.cpp @@ -13,7 +13,24 @@ AConfig::AConfig(const AConfig *parent) : parent_(parent) {} void AConfig::addDirective(const std::string &line) { - auto directive = DirectiveFactory::createDirective(line); + + std::size_t semicolon_count = 0; + for (char c : line) + { + if (c == ';') + { + ++semicolon_count; + } + } + + if (semicolon_count != 1 || line.back() != ';') + { + throw std::runtime_error("Directive must end with a single semicolon"); + } + + std::string trimmedLine = utils::trim(line, " \n\r\t;"); + Log::debug(" Adding directive: |" + trimmedLine + "| to config"); + auto directive = DirectiveFactory::createDirective(trimmedLine); if (directive) { directives_.emplace_back(std::move(directive));