Adds support for trim, left and right trim

This commit is contained in:
Felipe Zimmerle 2015-10-21 14:07:20 -03:00
parent 59af8ab842
commit 17faef565e
6 changed files with 13 additions and 13 deletions

View File

@ -101,9 +101,9 @@ Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(sha1) { return new Sha1(a); } IF_MATCH(sha1) { return new Sha1(a); }
IF_MATCH(sql_hex_decode) { return new SqlHexDecode(a); } IF_MATCH(sql_hex_decode) { return new SqlHexDecode(a); }
IF_MATCH(transformation) { return new Transformation(a); } IF_MATCH(transformation) { return new Transformation(a); }
IF_MATCH(trimLeft) { return new TrimLeft(a); }
IF_MATCH(trimRight) { return new TrimRight(a); }
IF_MATCH(trim) { return new Trim(a); } IF_MATCH(trim) { return new Trim(a); }
IF_MATCH(trim_left) { return new TrimLeft(a); }
IF_MATCH(trim_right) { return new TrimRight(a); }
IF_MATCH(url_decode) { return new UrlDecode(a); } IF_MATCH(url_decode) { return new UrlDecode(a); }
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); } IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
IF_MATCH(url_encode) { return new UrlEncode(a); } IF_MATCH(url_encode) { return new UrlEncode(a); }

View File

@ -40,7 +40,7 @@ TrimLeft::TrimLeft(std::string action)
std::string TrimLeft::evaluate(std::string value, std::string TrimLeft::evaluate(std::string value,
Assay *assay) { Assay *assay) {
return *trim(&value); return *ltrim(&value);
} }
} // namespace transformations } // namespace transformations

View File

@ -38,7 +38,7 @@ TrimRight::TrimRight(std::string action)
std::string TrimRight::evaluate(std::string value, std::string TrimRight::evaluate(std::string value,
Assay *assay) { Assay *assay) {
return *this->trim(&value); return *this->rtrim(&value);
} }
} // namespace transformations } // namespace transformations

@ -1 +1 @@
Subproject commit 967a8a43d1e91b65a05655c0d0a5754bdfa0759a Subproject commit 1f6f5235485e4a68f9cd57d2ac1ad4a0d4a7a3c4

View File

@ -64,8 +64,6 @@ void perform_unit_test(UnitTest *t, ModSecurityTestResults<UnitTest>* res) {
std::string ret = tfn->evaluate(t->input, NULL); std::string ret = tfn->evaluate(t->input, NULL);
t->obtained = 1; t->obtained = 1;
if (ret != t->output) { if (ret != t->output) {
std::cout << "ret: !" << ret << "!" << std::endl;
std::cout << "obt: !" << t->output << "!" << std::endl;
t->obtainedOutput = ret; t->obtainedOutput = ret;
res->push_back(t); res->push_back(t);
} }

View File

@ -21,7 +21,7 @@
#include <string> #include <string>
#include "common/colors.h" #include "common/colors.h"
#include "src/utils.h"
namespace modsecurity_test { namespace modsecurity_test {
@ -49,7 +49,7 @@ void replaceAll(std::string *s, const std::string &search,
break; break;
} }
s->erase(pos, search.length()); s->erase(pos, search.length());
s->insert(pos, &replace); s->insert(pos, &replace, 1);
} }
} }
@ -68,12 +68,12 @@ std::string UnitTest::print() {
i << " \"output\": \"" << this->output << "\"" << std::endl; i << " \"output\": \"" << this->output << "\"" << std::endl;
i << "}" << std::endl; i << "}" << std::endl;
if (this->ret != this->obtained) { if (this->ret != this->obtained) {
i << "Expecting: " << this->ret << " - operator returned: "; i << "Expecting: \"" << this->ret << "\" - returned: \"";
i << this->obtained << std::endl; i << this->obtained << "\"" << std::endl;
} }
if (this->output != this->obtainedOutput) { if (this->output != this->obtainedOutput) {
i << "Expecting: " << this->output << " - operator returned: "; i << "Expecting: \"" << ModSecurity::toHexIfNeeded(this->output) << "\" - returned: \"";
i << this->obtainedOutput << std::endl; i << ModSecurity::toHexIfNeeded(this->obtainedOutput) << "\"" << std::endl;
} }
return i.str(); return i.str();
@ -100,6 +100,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) {
replaceAll(&(u->input), "\\xc9", '\xc9'); replaceAll(&(u->input), "\\xc9", '\xc9');
replaceAll(&(u->input), "\\x3b", '\x3b'); replaceAll(&(u->input), "\\x3b", '\x3b');
replaceAll(&(u->input), "\\xFF", '\xff'); replaceAll(&(u->input), "\\xFF", '\xff');
replaceAll(&(u->input), "\\u0000", '\u0000');
} else if (strcmp(key, "name") == 0) { } else if (strcmp(key, "name") == 0) {
u->name = YAJL_GET_STRING(val); u->name = YAJL_GET_STRING(val);
} else if (strcmp(key, "type") == 0) { } else if (strcmp(key, "type") == 0) {
@ -108,6 +109,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) {
u->ret = YAJL_GET_INTEGER(val); u->ret = YAJL_GET_INTEGER(val);
} else if (strcmp(key, "output") == 0) { } else if (strcmp(key, "output") == 0) {
u->output = YAJL_GET_STRING(val); u->output = YAJL_GET_STRING(val);
replaceAll(&(u->output), "\\u0000", '\u0000');
} }
} }