diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 37b9d157e..adb3039d5 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -69,6 +69,9 @@ parseIniFile (std::string const& strInput, const bool bTrim) // Parse each line. for (auto& strValue : vLines) { + if (bTrim) + boost::algorithm::trim (strValue); + if (strValue.empty () || strValue[0] == '#') { // Blank line or comment, do nothing. @@ -82,9 +85,6 @@ parseIniFile (std::string const& strInput, const bool bTrim) else { // Another line for Section. - if (bTrim) - boost::algorithm::trim (strValue); - if (!strValue.empty ()) secResult[strSection].push_back (strValue); } diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index 62e8e198d..92a271f24 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -751,6 +751,42 @@ trustthesevalidators.gov BEAST_EXPECT(wss.admin_ip && (wss.admin_ip .get().size() == 1)); } + void testWhitespace() + { + Config cfg; + /* NOTE: this string includes some explicit + * space chars in order to verify proper trimming */ + std::string toLoad(R"( +[port_rpc])" "\x20" R"( +# comment + # indented comment +)" "\x20\x20" R"( +[ips])" "\x20" R"( +r.ripple.com 51235 + + [ips_fixed])" "\x20\x20" R"( + # COMMENT + s1.ripple.com 51235 + s2.ripple.com 51235 + +)"); + cfg.loadFromString (toLoad); + BEAST_EXPECT ( + cfg.exists ("port_rpc") && + cfg.section ("port_rpc").lines ().empty () && + cfg.section ("port_rpc").values ().empty ()); + BEAST_EXPECT ( + cfg.exists (SECTION_IPS) && + cfg.section (SECTION_IPS).lines ().size () == 1 && + cfg.section (SECTION_IPS).values ().size () == 1); + BEAST_EXPECT ( + cfg.exists (SECTION_IPS_FIXED) && + cfg.section (SECTION_IPS_FIXED).lines ().size () == 2 && + cfg.section (SECTION_IPS_FIXED).values ().size () == 2); + + } + + void run () override { testLegacy (); @@ -760,6 +796,7 @@ trustthesevalidators.gov testSetup (false); testSetup (true); testPort (); + testWhitespace (); } };