Commit ac479737 authored by Francis Dupont's avatar Francis Dupont

[5356] Improved decommentJSONFile to handle iPXE URLs

parent 22162983
...@@ -251,8 +251,7 @@ TEST(ParserTest, file) { ...@@ -251,8 +251,7 @@ TEST(ParserTest, file) {
configs.push_back("dhcpv4-over-dhcpv6.json"); configs.push_back("dhcpv4-over-dhcpv6.json");
configs.push_back("duid.json"); configs.push_back("duid.json");
configs.push_back("hooks.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("leases-expiration.json");
configs.push_back("multiple-options.json"); configs.push_back("multiple-options.json");
configs.push_back("mysql-reservations.json"); configs.push_back("mysql-reservations.json");
......
...@@ -69,8 +69,11 @@ std::string decommentJSONfile(const std::string& input_file) { ...@@ -69,8 +69,11 @@ std::string decommentJSONfile(const std::string& input_file) {
} }
// Second, let's get rid of the // comments // Second, let's get rid of the // comments
// at the beginning or after a control character.
size_t dblslash_pos = line.find("//"); 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); line = line.substr(0, dblslash_pos);
} }
......
...@@ -32,7 +32,7 @@ std::string readFile(const std::string& file_path); ...@@ -32,7 +32,7 @@ std::string readFile(const std::string& file_path);
/// token locations should remain unaffected. This is rather naive /// token locations should remain unaffected. This is rather naive
/// implementation, but it's probably sufficient for testing. It won't be able /// 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++ /// 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 /// @param input_file file to be stripped of comments
/// @return filename of a new file that has comments stripped from it /// @return filename of a new file that has comments stripped from it
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment