Skip to content

Commit 37868d1

Browse files
victorhoraFelipe Zimmerle
authored andcommitted
Add missing feature: t:uppercase transformation
1 parent 9d70345 commit 37868d1

File tree

9 files changed

+5929
-5771
lines changed

9 files changed

+5929
-5771
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ ACTIONS = \
167167
actions/transformations/trim.cc \
168168
actions/transformations/trim_left.cc \
169169
actions/transformations/trim_right.cc \
170+
actions/transformations/upper_case.cc \
170171
actions/transformations/url_decode.cc \
171172
actions/transformations/url_decode_uni.cc \
172173
actions/transformations/url_encode.cc \

src/actions/transformations/transformation.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "src/actions/transformations/trim.h"
5454
#include "src/actions/transformations/trim_left.h"
5555
#include "src/actions/transformations/trim_right.h"
56+
#include "src/actions/transformations/upper_case.h"
5657
#include "src/actions/transformations/url_decode.h"
5758
#include "src/actions/transformations/url_decode_uni.h"
5859
#include "src/actions/transformations/url_encode.h"
@@ -109,6 +110,7 @@ Transformation* Transformation::instantiate(std::string a) {
109110
IF_MATCH(trimLeft) { return new TrimLeft(a); }
110111
IF_MATCH(trimRight) { return new TrimRight(a); }
111112
IF_MATCH(trim) { return new Trim(a); }
113+
IF_MATCH(uppercase) { return new UpperCase(a); }
112114
IF_MATCH(urlDecodeUni) { return new UrlDecodeUni(a); }
113115
IF_MATCH(urlDecode) { return new UrlDecode(a); }
114116
IF_MATCH(urlEncode) { return new UrlEncode(a); }
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
#include "src/actions/transformations/upper_case.h"
17+
18+
#include <algorithm>
19+
#include <string>
20+
21+
#include "modsecurity/transaction.h"
22+
#include "src/actions/transformations/transformation.h"
23+
#include "modsecurity/actions/action.h"
24+
25+
namespace modsecurity {
26+
namespace actions {
27+
namespace transformations {
28+
29+
30+
UpperCase::UpperCase(std::string a)
31+
: Transformation(a) {
32+
}
33+
34+
std::string UpperCase::evaluate(std::string value,
35+
Transaction *transaction) {
36+
std::locale loc;
37+
38+
for (std::string::size_type i=0; i < value.length(); ++i) {
39+
value[i] = std::toupper(value[i], loc);
40+
}
41+
42+
return value;
43+
}
44+
45+
} // namespace transformations
46+
} // namespace actions
47+
} // namespace modsecurity
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address [email protected].
13+
*
14+
*/
15+
16+
#include <string>
17+
#include <unordered_map>
18+
19+
#include "modsecurity/actions/action.h"
20+
#include "src/actions/transformations/transformation.h"
21+
22+
#ifndef SRC_ACTIONS_TRANSFORMATIONS_UPPER_CASE_H_
23+
#define SRC_ACTIONS_TRANSFORMATIONS_UPPER_CASE_H_
24+
25+
#ifdef __cplusplus
26+
27+
namespace modsecurity {
28+
class Transaction;
29+
namespace actions {
30+
namespace transformations {
31+
32+
33+
class UpperCase : public Transformation {
34+
public:
35+
explicit UpperCase(std::string action);
36+
std::string evaluate(std::string exp,
37+
Transaction *transaction) override;
38+
};
39+
40+
} // namespace transformations
41+
} // namespace actions
42+
} // namespace modsecurity
43+
44+
#endif
45+
46+
#endif // SRC_ACTIONS_TRANSFORMATIONS_UPPER_CASE_H_

0 commit comments

Comments
 (0)