fix(3p/nix): Use SkipEmpty in all calls to absl::StrSplit

The behavior to return a list containing a single empty string when
provided an empty string is a behavior that absl inherited from legacy
code. However, the behavior expected by legacy code in Nix is the
behavior provided by the SkipEmpty option. Switch all calls to use
SkipEmpty, except for the call already using SkipWhitespace.

See also commit 26a59482d2, with the
partly-prophetic message: "there may be other places we need to
fix this as well."

Change-Id: I6e94856a12cfb1b7e4a3b4e221769ed446648861
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1687
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
Kane York 2020-08-06 01:28:00 -07:00 committed by kanepyork
parent 6a97206ceb
commit a5dae62e85
28 changed files with 80 additions and 55 deletions

View file

@ -181,7 +181,8 @@ struct CurlDownloader : public Downloader {
<< "': " << absl::StripAsciiWhitespace(line);
if (line.compare(0, 5, "HTTP/") == 0) { // new response starts
result.etag = "";
std::vector<std::string> ss = absl::StrSplit(line, absl::ByChar(' '));
std::vector<std::string> ss =
absl::StrSplit(line, absl::ByChar(' '), absl::SkipEmpty());
status = ss.size() >= 2 ? ss[1] : "";
result.data = std::make_shared<std::string>();
result.bodySize = 0;
@ -896,8 +897,8 @@ CachedDownloadResult Downloader::downloadCached(
storePath = readLink(fileLink);
store->addTempRoot(storePath);
if (store->isValidPath(storePath)) {
std::vector<std::string> ss =
absl::StrSplit(readFile(dataFile), absl::ByChar('\n'));
std::vector<std::string> ss = absl::StrSplit(
readFile(dataFile), absl::ByChar('\n'), absl::SkipEmpty());
if (ss.size() >= 3 && ss[0] == url) {
time_t lastChecked;
if (absl::SimpleAtoi(ss[2], &lastChecked) &&