Skip to content

Commit 7c30fcb

Browse files
committed
Replaced VALID_HEX, ISODIGIT & NBSP macros in string.h
- Moved them into modsecurity::utils::string to avoid polluting the global namespace.
1 parent 771cd8c commit 7c30fcb

8 files changed

+26
-16
lines changed

src/actions/transformations/css_decode.cc

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "src/utils/string.h"
1919

20+
using namespace modsecurity::utils::string;
2021

2122
namespace modsecurity::actions::transformations {
2223

src/actions/transformations/escape_seq_decode.cc

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "src/utils/string.h"
1919

20+
using namespace modsecurity::utils::string;
21+
2022
namespace modsecurity::actions::transformations {
2123

2224

src/actions/transformations/html_entity_decode.cc

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "src/compat/msvc.h"
2424
#endif
2525

26+
using namespace modsecurity::utils::string;
2627

2728
namespace modsecurity::actions::transformations {
2829

src/actions/transformations/js_decode.cc

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "src/utils/string.h"
1919

20+
using namespace modsecurity::utils::string;
2021

2122
namespace modsecurity::actions::transformations {
2223

src/actions/transformations/sql_hex_decode.cc

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "src/utils/string.h"
2121

22+
using namespace modsecurity::utils::string;
2223

2324
namespace modsecurity::actions::transformations {
2425

src/actions/transformations/url_decode_uni.cc

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "modsecurity/rules_set.h"
1919
#include "src/utils/string.h"
2020

21+
using namespace modsecurity::utils::string;
2122

2223
namespace modsecurity::actions::transformations {
2324

src/utils/decode.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "modsecurity/modsecurity.h"
1818
#include "src/utils/string.h"
1919

20+
using namespace modsecurity::utils::string;
2021

21-
namespace modsecurity {
22-
namespace utils {
22+
namespace modsecurity::utils {
2323

2424

2525
bool urldecode_nonstrict_inplace(std::string &val,
@@ -112,5 +112,4 @@ std::string uri_decode(const std::string & sSrc) {
112112
}
113113

114114

115-
} // namespace utils
116-
} // namespace modsecurity
115+
} // namespace modsecurity::utils

src/utils/string.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*
1414
*/
1515

16+
#ifndef SRC_UTILS_STRING_H_
17+
#define SRC_UTILS_STRING_H_
18+
1619
#include <ctime>
1720
#include <string>
1821
#include <cstring>
@@ -27,18 +30,21 @@
2730
#include "src/compat/msvc.h"
2831
#endif
2932

30-
#ifndef SRC_UTILS_STRING_H_
31-
#define SRC_UTILS_STRING_H_
33+
namespace modsecurity::utils::string {
3234

33-
#define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \
34-
((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F')))
35-
#define ISODIGIT(X) ((X >= '0') && (X <= '7'))
36-
#define NBSP 160
35+
template<typename CharT>
36+
constexpr bool VALID_HEX(CharT X) {
37+
return ((X >= '0') && (X <= '9'))
38+
|| ((X >= 'a') && (X <= 'f'))
39+
|| ((X >= 'A') && (X <= 'F'));
40+
}
3741

42+
template<typename CharT>
43+
constexpr bool ISODIGIT(CharT X) {
44+
return (X >= '0') && (X <= '7');
45+
}
3846

39-
namespace modsecurity {
40-
namespace utils {
41-
namespace string {
47+
constexpr char NBSP = 160;
4248

4349
const char HEX2DEC[256] = {
4450
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
@@ -271,8 +277,6 @@ inline std::string toupper(std::string str) { // cppcheck-suppress passedByValue
271277
}
272278

273279

274-
} // namespace string
275-
} // namespace utils
276-
} // namespace modsecurity
280+
} // namespace modsecurity::utils::string
277281

278282
#endif // SRC_UTILS_STRING_H_

0 commit comments

Comments
 (0)