mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds support for trim, left and right trim
This commit is contained in:
parent
59af8ab842
commit
17faef565e
@ -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); }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 967a8a43d1e91b65a05655c0d0a5754bdfa0759a
|
||||
Subproject commit 1f6f5235485e4a68f9cd57d2ac1ad4a0d4a7a3c4
|
@ -64,8 +64,6 @@ void perform_unit_test(UnitTest *t, ModSecurityTestResults<UnitTest>* 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);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <string>
|
||||
|
||||
#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');
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user