File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
src/actions/transformations Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,10 @@ namespace modsecurity::actions::transformations {
20
20
21
21
22
22
bool CmdLine::transform (std::string &value, const Transaction *trans) const {
23
- std::string ret ;
24
- int space = 0 ;
23
+ char *d = value. data () ;
24
+ bool space = false ;
25
25
26
- for (auto & a : value) {
26
+ for (const auto & a : value) {
27
27
switch (a) {
28
28
/* remove some characters */
29
29
case ' "' :
@@ -39,33 +39,34 @@ bool CmdLine::transform(std::string &value, const Transaction *trans) const {
39
39
case ' \t ' :
40
40
case ' \r ' :
41
41
case ' \n ' :
42
- if (space == 0 ) {
43
- ret. append ( " " ) ;
44
- space++ ;
42
+ if (space == false ) {
43
+ *d++ = ' ' ;
44
+ space = true ;
45
45
}
46
46
break ;
47
47
48
48
/* remove space before / or ( */
49
49
case ' /' :
50
50
case ' (' :
51
51
if (space) {
52
- ret. pop_back () ;
52
+ d-- ;
53
53
}
54
- space = 0 ;
55
- ret. append (&a, 1 ) ;
54
+ space = false ;
55
+ *d++ = a ;
56
56
break ;
57
57
58
58
/* copy normal characters */
59
59
default :
60
60
char b = std::tolower (a);
61
- ret. append (&b, 1 ) ;
62
- space = 0 ;
61
+ *d++ = b ;
62
+ space = false ;
63
63
break ;
64
64
}
65
65
}
66
66
67
- const auto changed = ret != value;
68
- value = ret;
67
+ const auto new_len = d - value.c_str ();
68
+ const auto changed = new_len != value.length ();
69
+ value.resize (new_len);
69
70
return changed;
70
71
}
71
72
You can’t perform that action at this time.
0 commit comments