Skip to content

Commit 883b804

Browse files
bjh7242zimmerle
authored andcommitted
adding removeWhitespace transformation
1 parent 0a60924 commit 883b804

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/actions/transformations/remove_whitespace.cc

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "modsecurity/transaction.h"
2626
#include "actions/transformations/transformation.h"
2727

28+
#define NBSP 160 // non breaking space char
2829

2930
namespace modsecurity {
3031
namespace actions {
@@ -37,18 +38,27 @@ RemoveWhitespace::RemoveWhitespace(std::string action)
3738

3839
std::string RemoveWhitespace::evaluate(std::string value,
3940
Transaction *transaction) {
40-
/**
41-
* @todo Implement the transformation RemoveWhitespace
42-
*/
43-
if (transaction) {
44-
#ifndef NO_LOGS
45-
transaction->debug(4, "Transformation RemoveWhitespace is " \
46-
"not implemented yet.");
47-
#endif
41+
42+
long int i = 0;
43+
44+
// loop through all the chars
45+
while(i < value.size()) {
46+
// remove whitespaces and non breaking spaces (NBSP)
47+
if (isspace(value[i])||(value[i] == NBSP)) {
48+
value.erase(i, 1);
49+
}
50+
else {
51+
/* if the space is not a whitespace char, increment counter
52+
counter should not be incremented if a character is erased because
53+
the index erased will be replaced by the following character */
54+
i++;
55+
}
4856
}
57+
4958
return value;
5059
}
5160

5261
} // namespace transformations
5362
} // namespace actions
5463
} // namespace modsecurity
64+

0 commit comments

Comments
 (0)