debugd: Remove extra blank line from GetOutputLines()
If the input file contains "a\nb\n", base::SplitString() will return a
vector {"a", "b", ""} because it treats "\n" as a delimiter, not a line
terminator. Removing the final "\n" fixes this.
BUG=chromium:821236
TEST=manually run `route` in crosh
Change-Id: I46f45e58195e7f3fe230d596fe74f366df676bf9
Reviewed-on: https://chromium-review.googlesource.com/972355
Commit-Ready: Kevin Cernekee <cernekee@chromium.org>
Tested-by: Kevin Cernekee <cernekee@chromium.org>
Reviewed-by: Kevin Cernekee <cernekee@chromium.org>
diff --git a/debugd/src/process_with_output.cc b/debugd/src/process_with_output.cc
index f9b3c29..396743b 100644
--- a/debugd/src/process_with_output.cc
+++ b/debugd/src/process_with_output.cc
@@ -8,6 +8,7 @@
#include <base/files/file_util.h>
#include <base/strings/string_split.h>
+#include <base/strings/string_util.h>
#include "debugd/src/error_utils.h"
@@ -71,6 +72,13 @@
if (!base::ReadFileToString(outfile_path_, &contents))
return false;
+ // If the file contains "a\nb\n", base::SplitString() will return a vector
+ // {"a", "b", ""} because it treats "\n" as a delimiter, not an EOL
+ // character. Removing the final "\n" fixes this.
+ if (base::EndsWith(contents, "\n", base::CompareCase::SENSITIVE)) {
+ contents.pop_back();
+ }
+
*output = base::SplitString(contents, "\n", base::KEEP_WHITESPACE,
base::SPLIT_WANT_ALL);
return true;