Skip to content

Commit

Permalink
UI: RuleTextParser: Fix bracket values end line
Browse files Browse the repository at this point in the history
  • Loading branch information
tnodir committed Nov 30, 2024
1 parent f63adad commit 17b54ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/tests/UtilTest/tst_ruletextparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ TEST_F(RuleTextParserTest, lineBracketValues)
ASSERT_EQ(p.ruleFilters().size(), 5);
}


TEST_F(RuleTextParserTest, lineIpPortSubList)
{
RuleTextParser p("{1}\n2");
Expand All @@ -418,3 +417,20 @@ TEST_F(RuleTextParserTest, lineIpPortSubList)

ASSERT_EQ(p.ruleFilters().size(), 7);
}

TEST_F(RuleTextParserTest, linesNotBracketValues)
{
RuleTextParser p("!(1.1.1.1)\n!(2.2.2.2)");

ASSERT_TRUE(p.parse());

ASSERT_EQ(p.ruleFilters().size(), 5);

// Check Last IP
{
const RuleFilter &rf = p.ruleFilters()[4];
ASSERT_TRUE(rf.isNot);
ASSERT_EQ(rf.type, FORT_RULE_FILTER_TYPE_ADDRESS);
checkStringList(rf.values, { "2.2.2.2" });
}
}
4 changes: 3 additions & 1 deletion src/ui/util/conf/ruletextparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ bool RuleTextParser::parseBracketValue(RuleCharTypes expectedSeparator)
}

if (hasParsedCharTypes(CharBracketEnd)) {
returnToCharType(CharBracketEnd); // Unget new lines
checkBracketValueEnd();
return false;
}

Expand Down Expand Up @@ -385,6 +385,8 @@ bool RuleTextParser::checkBracketValueEnd()
return false;
}

returnToCharType(CharBracketEnd); // Unget new lines

return true;
}

Expand Down

0 comments on commit 17b54ef

Please sign in to comment.