From af860e2eef615e829f9c2a5963ee1e11784c4301 Mon Sep 17 00:00:00 2001 From: Martin Vierula Date: Thu, 1 Dec 2022 11:19:26 -0800 Subject: [PATCH] Support comments in ipMatchFromFile file via '#' token --- CHANGES | 2 ++ src/utils/ip_tree.cc | 4 ++++ test/test-cases/data/ipMatchFromFile.txt | 1 + 3 files changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index edf1540d..e28b9a02 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ v3.x.y - YYYY-MMM-DD (to be released) ------------------------------------- + - Support comments in ipMatchFromFile file via '#' token + [Issue #2554 - @tomsommer, @martinhsv] - Fix: FILES_TMP_CONTENT collection key should use part name [Issue #2831 - @airween] - Use AS_HELP_STRING instead of obsolete AC_HELP_STRING macro diff --git a/src/utils/ip_tree.cc b/src/utils/ip_tree.cc index c4b7349d..df23280a 100644 --- a/src/utils/ip_tree.cc +++ b/src/utils/ip_tree.cc @@ -88,6 +88,10 @@ IpTree::~IpTree() { bool IpTree::addFromBuffer(std::istream *ss, std::string *error) { char *error_msg = NULL; for (std::string line; std::getline(*ss, line); ) { + size_t comment_start = line.find('#'); + if (comment_start != std::string::npos) { + line = line.substr(0, comment_start); + } int res = add_ip_from_param(line.c_str(), &m_tree, &error_msg); if (res != 0) { if (error_msg != NULL) { diff --git a/test/test-cases/data/ipMatchFromFile.txt b/test/test-cases/data/ipMatchFromFile.txt index d55f6085..97499f94 100644 --- a/test/test-cases/data/ipMatchFromFile.txt +++ b/test/test-cases/data/ipMatchFromFile.txt @@ -1,4 +1,5 @@ 127.0.0.1 +# Comment line 10.10.10.1 ::1 200.249.12.31