diff --git a/src/tests/UtilTest/tst_ruletextparser.h b/src/tests/UtilTest/tst_ruletextparser.h index 5f714666..89dccf57 100644 --- a/src/tests/UtilTest/tst_ruletextparser.h +++ b/src/tests/UtilTest/tst_ruletextparser.h @@ -64,3 +64,38 @@ TEST_F(RuleTextParserTest, lineIpPort) ASSERT_TRUE(compareStringList(rf.values, { "53" })); } } + +TEST_F(RuleTextParserTest, lineIpPortList) +{ + RuleTextParser p("1.1.1.1:53\n" + "2.2.2.2:64\n" + "3.3.3.3:75\n"); + + ASSERT_TRUE(p.parse()); + + ASSERT_EQ(p.ruleFilters().size(), 10); + + // Check IP + { + const RuleFilter &rf = p.ruleFilters()[5]; + ASSERT_TRUE(compareStringList(rf.values, { "2.2.2.2" })); + } + + // Check Port + { + const RuleFilter &rf = p.ruleFilters()[6]; + ASSERT_TRUE(compareStringList(rf.values, { "64" })); + } + + // Check IP + { + const RuleFilter &rf = p.ruleFilters()[8]; + ASSERT_TRUE(compareStringList(rf.values, { "3.3.3.3" })); + } + + // Check Port + { + const RuleFilter &rf = p.ruleFilters()[9]; + ASSERT_TRUE(compareStringList(rf.values, { "75" })); + } +} diff --git a/src/ui/util/conf/ruletextparser.cpp b/src/ui/util/conf/ruletextparser.cpp index ee2c1d9e..2e5879b9 100644 --- a/src/ui/util/conf/ruletextparser.cpp +++ b/src/ui/util/conf/ruletextparser.cpp @@ -26,6 +26,10 @@ RuleCharType processChar(const QChar c, const char *extraChars = nullptr) return CharDigit; } + if (c == '\n') { + return CharNewLine; + } + if (c.isSpace()) { return CharSpace; } @@ -414,20 +418,7 @@ bool RuleTextParser::parseChars( continue; } - if (hasError()) { - return false; - } - - ungetParsedChar(); - - return true; -} - -void RuleTextParser::ungetParsedChar() -{ - if (!isEmpty()) { - ungetChar(); - } + return !hasError(); } bool RuleTextParser::nextCharType( @@ -440,7 +431,7 @@ bool RuleTextParser::nextCharType( m_charType = CharNone; while (!isEmpty()) { - const QChar c = *m_p++; + const QChar c = *m_p; m_charType = getCharType(m_charType, c, extraChars); @@ -449,6 +440,8 @@ bool RuleTextParser::nextCharType( return false; } + ++m_p; + m_parsedCharTypes |= m_charType; if ((m_charType & skipCharTypes) == 0) diff --git a/src/ui/util/conf/ruletextparser.h b/src/ui/util/conf/ruletextparser.h index 3bcaa4da..5deda37f 100644 --- a/src/ui/util/conf/ruletextparser.h +++ b/src/ui/util/conf/ruletextparser.h @@ -119,8 +119,6 @@ private: bool parseChars(RuleCharTypes expectedCharTypes, RuleCharTypes skipCharTypes, const char *extraChars = nullptr); - void ungetParsedChar(); - bool nextCharType(RuleCharTypes expectedCharTypes, RuleCharTypes skipCharTypes, const char *extraChars = nullptr);