Disable token compress in str
There are certain cases where we use this split function, and we expect
tokens to be read out. For example:
/xyz/openbmc_project/sensors/unit/name
Should split into a "" in the first position. This use case is not
common, and a quick grep shows only two places in the code expect this
behavior. Boost::split has this behavior already, which is what this
function is emulating. While we could fix these, in the end they should
be following the rules outlined in COMMON_ERRORS.md, which disallow
this kind of parsing completely.
Tested: New unit tests passing.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iec3dcbf2b495b2b3b4ed419172c4133b16f7c65d
diff --git a/include/str_utility.hpp b/include/str_utility.hpp
index 39e1c82..7142583 100644
--- a/include/str_utility.hpp
+++ b/include/str_utility.hpp
@@ -14,10 +14,11 @@
{
size_t start = 0;
size_t end = 0;
- while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
+ while (end <= str.size())
{
end = str.find(delim, start);
strings.emplace_back(str.substr(start, end - start));
+ start = end + 1;
}
}
} // namespace bmcweb