From 883b804d90de93f9489732cff40885c82e32aa19 Mon Sep 17 00:00:00 2001 From: bjh7242 Date: Mon, 4 Apr 2016 23:27:02 +0000 Subject: [PATCH] adding removeWhitespace transformation --- .../transformations/remove_whitespace.cc | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/actions/transformations/remove_whitespace.cc b/src/actions/transformations/remove_whitespace.cc index 4c3f267c..d09453fc 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 +