From defb2ada613266f0b80dad921d35161b48fe1482 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sat, 13 Aug 2022 12:39:05 +0200 Subject: [PATCH] fixed pbm in extract_line : delete the line and the newline sequence character + fixed pbm n _cgi_pos : last return is npos, not pos --- README.md | 4 ++++ srcs/utils.cpp | 6 +++--- srcs/webserv/cgi_script.cpp | 15 +++++---------- srcs/webserv/response.cpp | 5 ++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 831a28f..ebc9a05 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ ## work together +#### next commit ++ fixed pbm in extract_line : delete the line and the newline sequence character ++ fixed pbm n _cgi_pos : last return is npos, not pos + #### TODO hugo - `_is_cgi()` and `_fill_cgi_path()` - two cgi tests : diff --git a/srcs/utils.cpp b/srcs/utils.cpp index c4536e0..d531b1b 100644 --- a/srcs/utils.cpp +++ b/srcs/utils.cpp @@ -198,8 +198,8 @@ std::string str_tolower(std::string str) } // identify a line in a string, by delim (ex. '\n') -// delete this line from the string -// and return the deleted line +// delete this line from the string (and the following nl sequence characters) +// and return the deleted line (without the followinf nl sequence characters) std::string extract_line(std::string & str, size_t pos, std::string delim) { @@ -220,7 +220,7 @@ std::string len = end - begin; del_str = str.substr(begin, len); - str.erase(begin, len); + str.erase(begin, len + delim.size()); return del_str; } diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index e928180..daf7ddb 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -8,32 +8,27 @@ size_t Webserv::_cgi_pos(Client *client, std::string &path) std::vector::const_iterator it; std::vector::const_iterator it_end; size_t pos = 0; - /*DEBUG*/ it = client->assigned_location->cgi_ext.begin(); std::cout << B_YELLOW << "\nDEBUG _cgi_pos()\n" << RESET << "vector_ext.size():[" << client->assigned_location->cgi_ext.size() << "]\n\n"; v_ext = client->assigned_location->cgi_ext; if (v_ext.empty()) - return NPOS; - /*DEBUG*/ std::cout << "ext:[" << *it << "]\n" << "path:[" << path << "]\n\n"; + return NPOS; /*DEBUG*/ std::cout << "ext:[" << *it << "]\n" << "path:[" << path << "]\n\n"; it_end = client->assigned_location->cgi_ext.end(); while (pos < path.size()) - { - /*DEBUG*/ std::cout << "\nwhile\n"; + { /*DEBUG*/ std::cout << "\nwhile\n"; if (path.compare(pos, 2, "./") == 0) - pos += 2; - /*DEBUG*/ std::cout << "&path[pos]:[" << &path[pos] << "]\n"; + pos += 2; /*DEBUG*/ std::cout << "&path[pos]:[" << &path[pos] << "]\n"; pos = path.find('.', pos); if (pos == NPOS) return pos; it = client->assigned_location->cgi_ext.begin(); for ( ; it != it_end; ++it) - { - /*DEBUG*/ std::cout << " for\n"; std::cout << " &path[pos]:[" << &path[pos] << "]\n" << " *it:[" << *it << "]\n" << " (*it).size():[" << (*it).size() << "]\n" << " path.substr(pos, (*it).size()):[" << path.substr(pos + 1, (*it).size()) << "]\n\n"; + { /*DEBUG*/ std::cout << " for\n"; std::cout << " &path[pos]:[" << &path[pos] << "]\n" << " *it:[" << *it << "]\n" << " (*it).size():[" << (*it).size() << "]\n" << " path.substr(pos, (*it).size()):[" << path.substr(pos + 1, (*it).size()) << "]\n\n"; if (path.compare(pos + 1, (*it).size(), *it) == 0) return pos; } pos++; } - return pos; + return NPOS; } std::string Webserv::_exec_cgi(Client *client) diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 302e20b..398ed76 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -71,10 +71,9 @@ void Webserv::_construct_response(Client *client) { std::string path = _replace_url_root(client, client->get_rq_abs_path()); - size_t pos = _cgi_pos(client, path); -//debug -std::cout << "pos:" << pos << B_YELLOW << "\nfin debug _cgi_pos()\n\n" << RESET; + size_t pos = _cgi_pos(client, path); /*DEBUG*/ std::cout << "pos:" << pos << B_YELLOW << "\nfin debug _cgi_pos()\n\n" << RESET; (void)pos; + // if (pos != NPOS) // { // client->fill_script_path(path, pos);