mirror of
https://github.com/tnodir/fort
synced 2024-11-14 22:19:05 +00:00
Tests: tst_ruletextparser.h: Add "lineIpValues" test
This commit is contained in:
parent
5c73dea22f
commit
8bb8ef1767
@ -65,6 +65,21 @@ TEST_F(RuleTextParserTest, lineIpPort)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, lineIpValues)
|
||||
{
|
||||
RuleTextParser p("(1.1.1.1/8, [2::]/16)");
|
||||
|
||||
ASSERT_TRUE(p.parse());
|
||||
|
||||
ASSERT_EQ(p.ruleFilters().size(), 3);
|
||||
|
||||
// Check IP Values
|
||||
{
|
||||
const RuleFilter &rf = p.ruleFilters()[2];
|
||||
ASSERT_TRUE(compareStringList(rf.values, { "1.1.1.1/8", "[2::]/16" }));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RuleTextParserTest, lineIpPortList)
|
||||
{
|
||||
RuleTextParser p("1.1.1.1:53\n"
|
||||
|
@ -289,7 +289,7 @@ void RuleTextParser::parseBracketValues()
|
||||
if (!parseBracketValue(expectedSeparator))
|
||||
break;
|
||||
|
||||
expectedSeparator = CharNewLine | CharValueSeparator;
|
||||
expectedSeparator = CharValueSeparator;
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,8 +297,8 @@ bool RuleTextParser::parseBracketValue(RuleCharTypes expectedSeparator)
|
||||
{
|
||||
resetParsedCharTypes();
|
||||
|
||||
if (!parseChars(CharValueBegin | CharValue,
|
||||
CharSpaceComment | CharBracketEnd | expectedSeparator, extraValueEndChars))
|
||||
if (!nextCharType(CharValueBegin | CharValue,
|
||||
CharLineBreak | CharBracketEnd | expectedSeparator, extraValueEndChars))
|
||||
return false;
|
||||
|
||||
if (hasParsedCharTypes(CharBracketEnd))
|
||||
@ -320,12 +320,23 @@ bool RuleTextParser::parseValue(bool expectValueEnd)
|
||||
|
||||
const char *extraChars = expectValueEnd ? extraValueEndChars : extraValueChars;
|
||||
|
||||
if (!parseChars(CharLetter | CharValue, extraChars))
|
||||
return false;
|
||||
for (;;) {
|
||||
if (!parseChars(CharLetter | CharValue, extraChars))
|
||||
return false;
|
||||
|
||||
if (expectValueEnd && m_charType != CharValueEnd) {
|
||||
setErrorMessage(tr("Unexpected end of value"));
|
||||
return false;
|
||||
if (expectValueEnd) {
|
||||
if (m_charType != CharValueEnd) {
|
||||
setErrorMessage(tr("Unexpected end of value"));
|
||||
return false;
|
||||
}
|
||||
|
||||
advanceCharPtr();
|
||||
|
||||
expectValueEnd = false;
|
||||
extraChars = extraValueChars;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const QStringView valueView(value, currentCharPtr() - value);
|
||||
@ -403,7 +414,7 @@ void RuleTextParser::endList(int nodeIndex)
|
||||
|
||||
bool RuleTextParser::skipComments(RuleCharTypes expectedCharTypes)
|
||||
{
|
||||
if (!nextCharType(expectedCharTypes, CharSpaceComment | CharNewLine))
|
||||
if (!nextCharType(expectedCharTypes, CharLineBreak))
|
||||
return false;
|
||||
|
||||
ungetChar();
|
||||
@ -436,11 +447,10 @@ bool RuleTextParser::nextCharType(
|
||||
m_charType = getCharType(m_charType, c, extraChars);
|
||||
|
||||
if (!checkNextCharType(expectedCharTypes, c)) {
|
||||
m_charType = CharNone;
|
||||
return false;
|
||||
}
|
||||
|
||||
++m_p;
|
||||
advanceCharPtr();
|
||||
|
||||
m_parsedCharTypes |= m_charType;
|
||||
|
||||
|
@ -31,6 +31,7 @@ enum RuleCharType : RuleCharTypes {
|
||||
CharName = (CharLetter | CharExtra), // a-zA-Z_
|
||||
CharValue = (CharDigit | CharExtra), // 0-9.-/:
|
||||
CharSpaceComment = (CharSpace | CharComment),
|
||||
CharLineBreak = (CharSpaceComment | CharNewLine),
|
||||
};
|
||||
|
||||
struct RuleFilter
|
||||
@ -98,9 +99,10 @@ private:
|
||||
void endList(int nodeIndex);
|
||||
|
||||
void resetParsedCharTypes() { m_parsedCharTypes = CharNone; }
|
||||
bool hasParsedCharTypes(RuleCharTypes v) { return v != 0 && (m_parsedCharTypes & v) != 0; }
|
||||
bool hasParsedCharTypes(RuleCharTypes v) { return v == 0 || (m_parsedCharTypes & v) != 0; }
|
||||
|
||||
void ungetChar() { --m_p; }
|
||||
void advanceCharPtr() { ++m_p; }
|
||||
|
||||
const QChar *currentCharPtr() const { return m_p; }
|
||||
const QChar *parsedCharPtr() const { return m_p - 1; }
|
||||
|
Loading…
Reference in New Issue
Block a user