mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
adding removeWhitespace transformation
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "actions/transformations/transformation.h"
|
#include "actions/transformations/transformation.h"
|
||||||
|
|
||||||
|
#define NBSP 160 // non breaking space char
|
||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
namespace actions {
|
namespace actions {
|
||||||
@@ -37,18 +38,27 @@ RemoveWhitespace::RemoveWhitespace(std::string action)
|
|||||||
|
|
||||||
std::string RemoveWhitespace::evaluate(std::string value,
|
std::string RemoveWhitespace::evaluate(std::string value,
|
||||||
Transaction *transaction) {
|
Transaction *transaction) {
|
||||||
/**
|
|
||||||
* @todo Implement the transformation RemoveWhitespace
|
long int i = 0;
|
||||||
*/
|
|
||||||
if (transaction) {
|
// loop through all the chars
|
||||||
#ifndef NO_LOGS
|
while(i < value.size()) {
|
||||||
transaction->debug(4, "Transformation RemoveWhitespace is " \
|
// remove whitespaces and non breaking spaces (NBSP)
|
||||||
"not implemented yet.");
|
if (isspace(value[i])||(value[i] == NBSP)) {
|
||||||
#endif
|
value.erase(i, 1);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* if the space is not a whitespace char, increment counter
|
||||||
|
counter should not be incremented if a character is erased because
|
||||||
|
the index erased will be replaced by the following character */
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace transformations
|
} // namespace transformations
|
||||||
} // namespace actions
|
} // namespace actions
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user