mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Adds support to the @endsWith operator
This commit is contained in:
parent
577736abb1
commit
209a3db47f
@ -22,37 +22,21 @@
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool EndsWith::evaluate(Assay *assay,
|
||||
std::string input) {
|
||||
// Check that the param is not longer than the input
|
||||
if (this->param.length() > input.length()) {
|
||||
return 0;
|
||||
|
||||
bool EndsWith::evaluate(Assay *assay, const std::string &input) {
|
||||
bool ret = false;
|
||||
if (input.length() >= param.length()) {
|
||||
ret = (0 == input.compare(input.length() - param.length(),
|
||||
param.length(), param));
|
||||
}
|
||||
|
||||
// Check that the input != the param
|
||||
if (this->param == input) {
|
||||
return 1;
|
||||
if (negation) {
|
||||
return !ret;
|
||||
}
|
||||
|
||||
// Start at the end of the input minus the size of the input
|
||||
std::string endString = input.substr(input.length() - \
|
||||
(this->param.length()), (this->param.length()));
|
||||
|
||||
// FIXME: We can make this smalle
|
||||
if (endString == this->param) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
EndsWith::EndsWith(std::string op, std::string param,
|
||||
bool negation)
|
||||
: Operator() {
|
||||
this->op = op;
|
||||
this->param = param;
|
||||
}
|
||||
|
||||
} // namespace operators
|
||||
} // namespace ModSecurity
|
||||
|
@ -27,8 +27,10 @@ namespace operators {
|
||||
class EndsWith : public Operator {
|
||||
public:
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
EndsWith(std::string o, std::string p, bool i);
|
||||
bool evaluate(Assay *assay, std::string exp);
|
||||
EndsWith(std::string op, std::string param, bool negation)
|
||||
: Operator(op, param, negation) { }
|
||||
|
||||
bool evaluate(Assay *assay, const std::string &str) override;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 93eddefff48e295179d6884691ecb24c362735be
|
||||
Subproject commit 55534e6966ebf037db68025eb2b3a14f056cd278
|
Loading…
x
Reference in New Issue
Block a user