From 4bf7f7a44c2b123950bad1e99b949c2e6bca7e7a Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 16 Sep 2015 11:22:57 -0300 Subject: [PATCH] Adds 'expandKeepOriginal' method to macro expansion class --- src/macro_expansion.cc | 15 ++++++++++++++- src/macro_expansion.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/macro_expansion.cc b/src/macro_expansion.cc index 788ff49e..84ba18e8 100644 --- a/src/macro_expansion.cc +++ b/src/macro_expansion.cc @@ -20,13 +20,26 @@ namespace ModSecurity { MacroExpansion::MacroExpansion() { } + +std::string MacroExpansion::expandKeepOriginal(const std::string& input, + Assay *assay) { + std::string a = MacroExpansion::expand(input, assay); + + if (a != input) { + return "\"" + a + "\" (Was: " + input + ")"; + } + + return input; +} + + std::string MacroExpansion::expand(const std::string& input, Assay *assay) { std::string res(input); size_t pos = res.find("%{"); while (pos != std::string::npos) { size_t start = pos; - size_t end = res.find("}%"); + size_t end = res.find("}"); if (end == std::string::npos) { return res; } diff --git a/src/macro_expansion.h b/src/macro_expansion.h index ae4163dd..e83139b6 100644 --- a/src/macro_expansion.h +++ b/src/macro_expansion.h @@ -32,6 +32,7 @@ class MacroExpansion { MacroExpansion(); static std::string expand(const std::string& input, Assay *assay); + static std::string expandKeepOriginal(const std::string& input, Assay *assay); };