mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-30 03:34:26 +03:00
sync code
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_KEYWORD);
|
||||
|
||||
static const string whitespaces = " \t";
|
||||
|
||||
static string
|
||||
@@ -14,6 +16,13 @@ getSubStrNoPadding(const string &str, uint start, uint end)
|
||||
auto r_end = str.find_last_not_of(whitespaces, end-1);
|
||||
|
||||
if (r_end==string::npos || r_start==string::npos || r_start>r_end) {
|
||||
dbgWarning(D_KEYWORD)
|
||||
<< "Can't extract substring from '"
|
||||
<< str
|
||||
<< "', padded start: "
|
||||
<< r_start
|
||||
<< ", padded end: "
|
||||
<< r_end;
|
||||
throw KeywordError("Found an empty section in the '"+ str + "'");
|
||||
}
|
||||
|
||||
@@ -45,13 +54,24 @@ split(const string &str, const string &delim, uint start = 0)
|
||||
}
|
||||
default:
|
||||
if (!in_string && delim.find(str[index])!=string::npos) {
|
||||
res.push_back(getSubStrNoPadding(str, part_start, index));
|
||||
if (part_start == index) {
|
||||
dbgTrace(D_KEYWORD) << "Encountered consecutive delimiter in: " << str;
|
||||
} else {
|
||||
res.push_back(getSubStrNoPadding(str, part_start, index));
|
||||
}
|
||||
part_start = index+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (escape||in_string) throw KeywordError("Split has ended in the middle of the parsing");
|
||||
if (escape||in_string) {
|
||||
dbgWarning(D_KEYWORD)
|
||||
<< "Failed to split "
|
||||
<< str
|
||||
<< ". Split ended in "
|
||||
<< (escape ? "escape" : "middle of string");
|
||||
throw KeywordError("Split has ended in the middle of the parsing");
|
||||
}
|
||||
|
||||
if (str.find_first_not_of(whitespaces, part_start)!=string::npos) {
|
||||
res.push_back(getSubStrNoPadding(str, part_start, str.size()));
|
||||
|
@@ -55,6 +55,13 @@ TEST_F(KeywordsRuleTest, data_basic_test) {
|
||||
EXPECT_FALSE(ruleRun("data: \"75\", part HTTP_RESPONSE_BODY;"));
|
||||
}
|
||||
|
||||
TEST_F(KeywordsRuleTest, consecutive_delimiter_test) {
|
||||
appendBuffer("HTTP_RESPONSE_BODY", "123456789");
|
||||
|
||||
EXPECT_TRUE(ruleRun("data: \"234\" , part HTTP_RESPONSE_BODY;"));
|
||||
EXPECT_FALSE(ruleRun("data: \"75\", part HTTP_RESPONSE_BODY;"));
|
||||
}
|
||||
|
||||
TEST_F(KeywordsRuleTest, data_relative_test) {
|
||||
appendBuffer("HTTP_RESPONSE_BODY", "1234567890");
|
||||
|
||||
|
Reference in New Issue
Block a user