diff --git a/src/actions/transformations/remove_whitespace.cc b/src/actions/transformations/remove_whitespace.cc index 4c3f267cce..d09453fc24 100644 --- a/src/actions/transformations/remove_whitespace.cc +++ b/src/actions/transformations/remove_whitespace.cc @@ -25,6 +25,7 @@ #include "modsecurity/transaction.h" #include "actions/transformations/transformation.h" +#define NBSP 160 // non breaking space char namespace modsecurity { namespace actions { @@ -37,18 +38,27 @@ RemoveWhitespace::RemoveWhitespace(std::string action) std::string RemoveWhitespace::evaluate(std::string value, Transaction *transaction) { - /** - * @todo Implement the transformation RemoveWhitespace - */ - if (transaction) { -#ifndef NO_LOGS - transaction->debug(4, "Transformation RemoveWhitespace is " \ - "not implemented yet."); -#endif + + long int i = 0; + + // loop through all the chars + while(i < value.size()) { + // remove whitespaces and non breaking spaces (NBSP) + if (isspace(value[i])||(value[i] == NBSP)) { + 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; } } // namespace transformations } // namespace actions } // namespace modsecurity + diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index 8f3b5d70f2..ae4cbf72ab 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -98,7 +98,7 @@ Transformation* Transformation::instantiate(std::string a) { IF_MATCH(removeCommentsChar) { return new RemoveCommentsChar(a); } IF_MATCH(remove_comments) { return new RemoveComments(a); } IF_MATCH(removeNulls) { return new RemoveNulls(a); } - IF_MATCH(remove_whitespace) { return new RemoveWhitespace(a); } + IF_MATCH(removeWhitespace) { return new RemoveWhitespace(a); } IF_MATCH(compressWhitespace) { return new CompressWhitespace(a); } IF_MATCH(replaceComments) { return new ReplaceComments(a); } IF_MATCH(replaceNulls) { return new ReplaceNulls(a); }