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 {
2020
2121
2222bool 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 ;
2525
26- for (auto & a : value) {
26+ for (const auto & a : value) {
2727 switch (a) {
2828 /* remove some characters */
2929 case ' "' :
@@ -39,33 +39,34 @@ bool CmdLine::transform(std::string &value, const Transaction *trans) const {
3939 case ' \t ' :
4040 case ' \r ' :
4141 case ' \n ' :
42- if (space == 0 ) {
43- ret. append ( " " ) ;
44- space++ ;
42+ if (space == false ) {
43+ *d++ = ' ' ;
44+ space = true ;
4545 }
4646 break ;
4747
4848 /* remove space before / or ( */
4949 case ' /' :
5050 case ' (' :
5151 if (space) {
52- ret. pop_back () ;
52+ d-- ;
5353 }
54- space = 0 ;
55- ret. append (&a, 1 ) ;
54+ space = false ;
55+ *d++ = a ;
5656 break ;
5757
5858 /* copy normal characters */
5959 default :
6060 char b = std::tolower (a);
61- ret. append (&b, 1 ) ;
62- space = 0 ;
61+ *d++ = b ;
62+ space = false ;
6363 break ;
6464 }
6565 }
6666
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);
6970 return changed;
7071}
7172
You can’t perform that action at this time.
0 commit comments