diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index eaa97708..430d922e 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -101,9 +101,9 @@ Transformation* Transformation::instantiate(std::string a) { IF_MATCH(sha1) { return new Sha1(a); } IF_MATCH(sql_hex_decode) { return new SqlHexDecode(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_left) { return new TrimLeft(a); } - IF_MATCH(trim_right) { return new TrimRight(a); } IF_MATCH(url_decode) { return new UrlDecode(a); } IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); } IF_MATCH(url_encode) { return new UrlEncode(a); } diff --git a/src/actions/transformations/trim_left.cc b/src/actions/transformations/trim_left.cc index 403b8ae9..90f33019 100644 --- a/src/actions/transformations/trim_left.cc +++ b/src/actions/transformations/trim_left.cc @@ -40,7 +40,7 @@ TrimLeft::TrimLeft(std::string action) std::string TrimLeft::evaluate(std::string value, Assay *assay) { - return *trim(&value); + return *ltrim(&value); } } // namespace transformations diff --git a/src/actions/transformations/trim_right.cc b/src/actions/transformations/trim_right.cc index dab935db..4ce6c7ed 100644 --- a/src/actions/transformations/trim_right.cc +++ b/src/actions/transformations/trim_right.cc @@ -38,7 +38,7 @@ TrimRight::TrimRight(std::string action) std::string TrimRight::evaluate(std::string value, Assay *assay) { - return *this->trim(&value); + return *this->rtrim(&value); } } // namespace transformations diff --git a/test/test-cases/secrules-language-tests b/test/test-cases/secrules-language-tests index 967a8a43..1f6f5235 160000 --- a/test/test-cases/secrules-language-tests +++ b/test/test-cases/secrules-language-tests @@ -1 +1 @@ -Subproject commit 967a8a43d1e91b65a05655c0d0a5754bdfa0759a +Subproject commit 1f6f5235485e4a68f9cd57d2ac1ad4a0d4a7a3c4 diff --git a/test/unit/unit.cc b/test/unit/unit.cc index 801af38a..43a3d4d5 100644 --- a/test/unit/unit.cc +++ b/test/unit/unit.cc @@ -64,8 +64,6 @@ void perform_unit_test(UnitTest *t, ModSecurityTestResults* res) { std::string ret = tfn->evaluate(t->input, NULL); t->obtained = 1; if (ret != t->output) { - std::cout << "ret: !" << ret << "!" << std::endl; - std::cout << "obt: !" << t->output << "!" << std::endl; t->obtainedOutput = ret; res->push_back(t); } diff --git a/test/unit/unit_test.cc b/test/unit/unit_test.cc index a1fdae80..341abafc 100644 --- a/test/unit/unit_test.cc +++ b/test/unit/unit_test.cc @@ -21,7 +21,7 @@ #include #include "common/colors.h" - +#include "src/utils.h" namespace modsecurity_test { @@ -49,7 +49,7 @@ void replaceAll(std::string *s, const std::string &search, break; } 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 << "}" << std::endl; if (this->ret != this->obtained) { - i << "Expecting: " << this->ret << " - operator returned: "; - i << this->obtained << std::endl; + i << "Expecting: \"" << this->ret << "\" - returned: \""; + i << this->obtained << "\"" << std::endl; } if (this->output != this->obtainedOutput) { - i << "Expecting: " << this->output << " - operator returned: "; - i << this->obtainedOutput << std::endl; + i << "Expecting: \"" << ModSecurity::toHexIfNeeded(this->output) << "\" - returned: \""; + i << ModSecurity::toHexIfNeeded(this->obtainedOutput) << "\"" << std::endl; } return i.str(); @@ -100,6 +100,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) { replaceAll(&(u->input), "\\xc9", '\xc9'); replaceAll(&(u->input), "\\x3b", '\x3b'); replaceAll(&(u->input), "\\xFF", '\xff'); + replaceAll(&(u->input), "\\u0000", '\u0000'); } else if (strcmp(key, "name") == 0) { u->name = YAJL_GET_STRING(val); } else if (strcmp(key, "type") == 0) { @@ -108,6 +109,7 @@ UnitTest *UnitTest::from_yajl_node(yajl_val &node) { u->ret = YAJL_GET_INTEGER(val); } else if (strcmp(key, "output") == 0) { u->output = YAJL_GET_STRING(val); + replaceAll(&(u->output), "\\u0000", '\u0000'); } }