From: Francis Dupont Date: Thu, 19 Oct 2017 11:16:27 +0000 (+0200) Subject: [5356] Improved decommentJSONFile to handle iPXE URLs X-Git-Tag: trac5389_base~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac47973785c617ce199e92c953711968da5ece2e;p=thirdparty%2Fkea.git [5356] Improved decommentJSONFile to handle iPXE URLs --- diff --git a/src/bin/dhcp6/tests/parser_unittest.cc b/src/bin/dhcp6/tests/parser_unittest.cc index fcb20b638e..fdc9c85f38 100644 --- a/src/bin/dhcp6/tests/parser_unittest.cc +++ b/src/bin/dhcp6/tests/parser_unittest.cc @@ -251,8 +251,7 @@ TEST(ParserTest, file) { configs.push_back("dhcpv4-over-dhcpv6.json"); configs.push_back("duid.json"); configs.push_back("hooks.json"); - // Removed because decommentJSON does not work with URLs - // configs.push_back("iPXE.json"); + configs.push_back("iPXE.json"); configs.push_back("leases-expiration.json"); configs.push_back("multiple-options.json"); configs.push_back("mysql-reservations.json"); diff --git a/src/lib/testutils/io_utils.cc b/src/lib/testutils/io_utils.cc index 0081707e97..93558a4d46 100644 --- a/src/lib/testutils/io_utils.cc +++ b/src/lib/testutils/io_utils.cc @@ -69,8 +69,11 @@ std::string decommentJSONfile(const std::string& input_file) { } // Second, let's get rid of the // comments + // at the beginning or after a control character. size_t dblslash_pos = line.find("//"); - if (dblslash_pos != string::npos) { + if ((dblslash_pos != string::npos) && + ((dblslash_pos == 0) || + ((unsigned) line[dblslash_pos - 1] <= 32))) { line = line.substr(0, dblslash_pos); } diff --git a/src/lib/testutils/io_utils.h b/src/lib/testutils/io_utils.h index ce4b57ccf2..58fd015706 100644 --- a/src/lib/testutils/io_utils.h +++ b/src/lib/testutils/io_utils.h @@ -32,7 +32,7 @@ std::string readFile(const std::string& file_path); /// token locations should remain unaffected. This is rather naive /// implementation, but it's probably sufficient for testing. It won't be able /// to pick any trickier cases, like # or // appearing in strings, nested C++ -/// comments etc. +/// comments etc at the exception of // in URLs. /// /// @param input_file file to be stripped of comments /// @return filename of a new file that has comments stripped from it